Skip to content

sqlreview: structured-DDL rules from JSqlParser 5.4 (NOT NULL without default, CREATE INDEX without CONCURRENTLY, …) #1079

Description

@babltiga

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendenhancementNew feature or requestjavaPull requests that update java code

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions