Context
JSqlParser 5.4 (#1077) now parses DDL into structured parts that 5.3 only kept as raw text:
ALTER COLUMN nullability actions and default expressions
- column data types with precision / scale as properties
- PostgreSQL
CREATE INDEX clauses (CONCURRENTLY, INCLUDE, partial WHERE, …)
- column defaults in
CREATE TABLE
That lets the deterministic SQL review engine (#860, docs/19-sql-review.md) check migrations for dangerous shapes from the AST alone, which also benefits schema change set authoring (#870). There, a BLOCK refuses the save.
Proposal
Add built-in rules to sqlreview/internal/rules/SqlRuleCatalog, for example:
add_not_null_column_without_default: ALTER TABLE … ADD COLUMN … NOT NULL with no DEFAULT fails, or rewrites the table, on a non-empty table.
create_index_without_concurrently (PostgreSQL): a plain CREATE INDEX takes a lock that blocks writes to the table.
column_type_narrowing: ALTER COLUMN … TYPE to a shorter length or lower precision / scale can truncate data or fail.
set_not_null_on_existing_column: ALTER COLUMN … SET NOT NULL scans the whole table under an exclusive lock.
Pick the final set and the default severities during implementation.
Acceptance criteria
- Each rule is AST-only, follows the
SqlRule contract, and has name / description / message keys in every messages file (MessagesParityTest).
- Dialect-specific rules report
applicable:false (or skip) on engines where they don't apply.
- A unit test per rule, following the existing
*RuleTest pattern (parse → evaluate → findings).
- The rules appear in the
GET /sql-review/rules catalog and on the /admin/sql-review page with no frontend change beyond locale strings.
- docs/19-sql-review.md lists the new rules.
Depends on #1077 (JSqlParser 5.4).
Context
JSqlParser 5.4 (#1077) now parses DDL into structured parts that 5.3 only kept as raw text:
ALTER COLUMNnullability actions and default expressionsCREATE INDEXclauses (CONCURRENTLY,INCLUDE, partialWHERE, …)CREATE TABLEThat lets the deterministic SQL review engine (#860, docs/19-sql-review.md) check migrations for dangerous shapes from the AST alone, which also benefits schema change set authoring (#870). There, a
BLOCKrefuses the save.Proposal
Add built-in rules to
sqlreview/internal/rules/SqlRuleCatalog, for example:add_not_null_column_without_default:ALTER TABLE … ADD COLUMN … NOT NULLwith noDEFAULTfails, or rewrites the table, on a non-empty table.create_index_without_concurrently(PostgreSQL): a plainCREATE INDEXtakes a lock that blocks writes to the table.column_type_narrowing:ALTER COLUMN … TYPEto a shorter length or lower precision / scale can truncate data or fail.set_not_null_on_existing_column:ALTER COLUMN … SET NOT NULLscans the whole table under an exclusive lock.Pick the final set and the default severities during implementation.
Acceptance criteria
SqlRulecontract, and has name / description / message keys in every messages file (MessagesParityTest).applicable:false(or skip) on engines where they don't apply.*RuleTestpattern (parse → evaluate → findings).GET /sql-review/rulescatalog and on the/admin/sql-reviewpage with no frontend change beyond locale strings.Depends on #1077 (JSqlParser 5.4).