Skip to content

feat(schema): ignore listed statements and locate rejected ones - #46

Merged
omer-cengel merged 2 commits into
masterfrom
feature/ignored-schema-statements
Sep 27, 2026
Merged

omer-cengel merged 2 commits into
masterfrom
feature/ignored-schema-statements

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

Migration histories contain many statements that never change a table's columns, types, or nullability, such as indexes, grants, functions, triggers, comments, and seed data. Schema sources now accept a documented list of these statements and leave the schema model unchanged, so an existing migration directory loads without edits. Every other statement is still rejected, and the diagnostic now names the line the statement begins on.

Changes

  • Accept and ignore CREATE/ALTER/DROP INDEX, COMMENT ON TABLE/COLUMN/VIEW, CREATE EXTENSION, CREATE/ALTER/DROP SEQUENCE, GRANT, REVOKE, CREATE [OR REPLACE] FUNCTION with an untagged $$ ... $$ body, DROP FUNCTION, CREATE/DROP TRIGGER, INSERT, UPDATE, DELETE, and CREATE TYPE ... AS ENUM. Ignored statements are not resolved against the schema.
  • Accept and ignore the ALTER TABLE constraint actions: ADD [CONSTRAINT name] PRIMARY KEY, UNIQUE, or FOREIGN KEY, ADD CONSTRAINT name CHECK, DROP CONSTRAINT [IF EXISTS], and RENAME CONSTRAINT. They may stand alone or beside modeled actions. The altered table must still exist.
  • Reject a CREATE FUNCTION whose own body is not dollar-quoted at the line it begins on, even when the parser captures a later dollar-quoted function into it.
  • Report every other statement as Unsupported schema statement: <kind> at line <n>. The line is derived from the parser's token chain, so comments and multi-line function bodies do not shift it. The compiler prefixes the message with the failing migration file.
  • Document the ignored list, the parser limitations (untagged $$ only, with tagged delimiters such as $body$ being a syntax error; COMMENT ON limited to TABLE, COLUMN, and VIEW; unnamed ADD CHECK being a syntax error), and the new diagnostic.

Scope and non-goals

  • Ignored statements and constraint actions are not modeled; constraints an ALTER TABLE adds are not recorded.
  • SQL is not split or pre-processed to work around parser limitations, so tagged dollar quotes and other COMMENT ON targets remain syntax errors.
  • Other ALTER TABLE actions such as SET DEFAULT, other DROP objects such as views, ALTER TYPE, and every other statement kind remain rejected. Missing-reference and syntax diagnostics are unchanged.

Schema sources now accept index, comment, extension, sequence, grant,
function, trigger, data, enum-type, and constraint ALTER TABLE statements
without changing the schema model. A CREATE FUNCTION is ignored only when
its own declaration has a dollar-quoted body. Every other statement fails
as "Unsupported schema statement: <kind> at line <n>", where the line is
read from the parse tree's token chain.
@omer-cengel
omer-cengel merged commit fddf15c into master Sep 27, 2026
6 checks passed
@omer-cengel
omer-cengel deleted the feature/ignored-schema-statements branch September 27, 2026 21:38
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