--- description: "SQL and database migration conventions: naming, safety, parameterized queries, indexing, Postgres" globs: ["**/*.sql", "**/migrations/**", "**/Migrations/**"] --- # SQL / Migrations - Use lowercase for SQL keywords (or match project convention); snake_case for table/column names - Every migration must be reversible (include DOWN/rollback) - Never rename tables or columns without explicit confirmation — prefer additive changes - Use parameterized queries; never concatenate user input into SQL - Add indexes for columns used in WHERE, JOIN, ORDER BY - Use transactions for multi-step data changes - Include `NOT NULL` constraints by default; explicitly allow `NULL` only when needed - Name constraints explicitly: `pk_table`, `fk_table_column`, `idx_table_column` - Test migrations against a copy of production schema before applying