Skip to content

feat(schema): ignore unmodeled statements and report errors in SQL terms - #63

Merged
omer-cengel merged 1 commit into
masterfrom
feature/one-rule-for-ignored-schema-statements
Oct 10, 2026
Merged

omer-cengel merged 1 commit into
masterfrom
feature/one-rule-for-ignored-schema-statements

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

Schema files record a database's whole history, so a fixed list of accepted statements kept stopping real migration histories on views, schemas, session settings, policies, domains, or composite types. sqlcj now applies one rule: only the table and enum statements it models change the schema, and every other parsed statement is accepted without being resolved against the schema. Statements that are still rejected are reported in SQL terms with their line instead of internal parser class names.

Changes

  • CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE TYPE ... AS ENUM, and ALTER TYPE ... ADD VALUE update the schema model; every other parsed statement is ignored, including CREATE/DROP VIEW, materialized views, CREATE/DROP SCHEMA, SET, RESET, TRUNCATE, SELECT, policies, roles, default privileges, domains, procedures, and opaque statements such as ALTER FUNCTION or CREATE CAST.
  • A composite, range, or shell CREATE TYPE is ignored; a column of such a type is recorded with its declared type like any other unmapped type.
  • Ignored statements are not resolved against the schema, so a view over or a TRUNCATE of an unmodeled table is accepted.
  • Rejections now use SQL-term messages:
    • Unsupported ALTER TABLE action at line <n>
    • Unsupported ALTER TYPE action at line <n>
    • Unsupported schema statement: CREATE FUNCTION without a dollar-quoted body at line <n> (or CREATE PROCEDURE)
    • Unsupported schema statement: <opening words> at line <n> for an opaque statement that opens as table or type DDL, such as ALTER FOREIGN TABLE
  • The PostgreSQL support documentation describes the rule, the rejected forms and their diagnostics, and that DDL inside DO blocks or function bodies and columns removed by DROP TYPE ... CASCADE are not seen.

Scope and non-goals

  • ALTER TABLE actions other than the modeled forms and the existing constraint actions are still rejected; classifying them is not part of this change.
  • ALTER TYPE actions other than ADD VALUE are still rejected, and enum renames are not modeled.
  • A function or procedure whose body is not dollar-quoted is still rejected, because the parser would otherwise consume the statements after it.
  • Statements the parser cannot read at all, such as DO blocks and DROP TYPE, remain syntax errors; schema qualifiers, LIKE, PARTITION OF, and AS SELECT tables are unchanged.

Only CREATE/ALTER/DROP TABLE, CREATE TYPE ... AS ENUM, and
ALTER TYPE ... ADD VALUE change the schema model; every other parsed
statement, including views, schemas, session statements, TRUNCATE,
policies, roles, domains, and non-enum CREATE TYPE, is now ignored
without being resolved against the schema.

Statements that may still change the model are rejected with SQL-term
messages instead of parser class names: unsupported ALTER TABLE and
ALTER TYPE actions, functions or procedures without a dollar-quoted
body, and opaque statements that open as table or type DDL, such as
ALTER FOREIGN TABLE.
@omer-cengel
omer-cengel merged commit aa3475e into master Oct 10, 2026
7 of 13 checks passed
@omer-cengel
omer-cengel deleted the feature/one-rule-for-ignored-schema-statements branch October 10, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant