feat(lint): add linter rules for migration and naming conventions
* Implement migration safety rules: - MIG001: Warn on CREATE INDEX without CONCURRENT. - MIG002: Warn on ALTER TABLE ADD COLUMN NOT NULL without DEFAULT. - MIG003: Warn on ALTER TABLE ADD CONSTRAINT without NOT VALID. * Implement naming conventions rules: - NAM001: Warn on non-snake_case table names. - NAM002: Warn on non-snake_case column names in CREATE TABLE. - NAM003: Warn on non-snake_case function names. * Add test fixtures for all new rules.
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
-- Fixtures for correctness rules (COR001-COR003).
|
||||
|
||||
-- COR001: SELECT *
|
||||
SELECT * FROM orders;
|
||||
|
||||
-- COR002: UPDATE without WHERE
|
||||
UPDATE orders SET status = 'archived';
|
||||
|
||||
-- COR003: DELETE without WHERE
|
||||
DELETE FROM orders;
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
-- Fixtures for migration safety rules — all statements are safe.
|
||||
|
||||
-- MIG001 safe: CONCURRENTLY
|
||||
CREATE INDEX CONCURRENTLY idx_orders_user ON orders(user_id);
|
||||
|
||||
-- MIG002 safe: nullable column (no NOT NULL)
|
||||
ALTER TABLE orders ADD COLUMN note text;
|
||||
|
||||
-- MIG002 safe: NOT NULL with a DEFAULT
|
||||
ALTER TABLE orders ADD COLUMN status text NOT NULL DEFAULT 'pending';
|
||||
|
||||
-- MIG003 safe: FK with NOT VALID
|
||||
ALTER TABLE orders
|
||||
ADD CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id) NOT VALID;
|
||||
|
||||
-- MIG003 safe: CHECK with NOT VALID
|
||||
ALTER TABLE orders ADD CONSTRAINT chk_positive CHECK (amount > 0) NOT VALID;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
-- Fixtures for migration safety rules (MIG001-MIG003).
|
||||
-- Every statement here should trigger at least one finding.
|
||||
|
||||
-- MIG001: non-concurrent index
|
||||
CREATE INDEX idx_orders_user ON orders(user_id);
|
||||
|
||||
-- MIG002: ADD COLUMN NOT NULL without DEFAULT
|
||||
ALTER TABLE orders ADD COLUMN status text NOT NULL;
|
||||
|
||||
-- MIG003: ADD FOREIGN KEY without NOT VALID
|
||||
ALTER TABLE orders
|
||||
ADD CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id);
|
||||
|
||||
-- MIG003: ADD CHECK without NOT VALID
|
||||
ALTER TABLE orders ADD CONSTRAINT chk_positive CHECK (amount > 0);
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
-- Fixtures for naming rules (NAM001-NAM003).
|
||||
-- Quoted identifiers preserve case in the PG parse tree; unquoted identifiers
|
||||
-- are always folded to lowercase by the parser and cannot violate snake_case.
|
||||
|
||||
-- NAM001: quoted CamelCase table name
|
||||
CREATE TABLE "UserAccounts" (
|
||||
-- NAM002: quoted camelCase column names
|
||||
"userId" integer PRIMARY KEY,
|
||||
"emailAddress" text NOT NULL
|
||||
);
|
||||
|
||||
-- NAM003: quoted CamelCase function name
|
||||
CREATE FUNCTION "GetUserById"(p_id integer) RETURNS text LANGUAGE sql AS $$
|
||||
SELECT email FROM users WHERE id = p_id
|
||||
$$;
|
||||
Reference in New Issue
Block a user