Repository navigation
feat(schema): split schema sources so unreadable statements fail alone - #64
Merged
Merged
Conversation
Split each schema source at the statement separators JSqlParser's own token manager reports and parse every statement alone. A tagged dollar-quoted body ends at the next occurrence of its delimiter, and psql meta-command lines such as \restrict are blanked before lexing. A statement the parser cannot read is ignored unless it opens as table or type DDL. An unreadable ALTER TABLE whose every top-level action adds a constraint or an identity is ignored without resolving its table, which lets pg_dump identity columns load. Any other unreadable table or type statement is rejected with the parser's reason at its file line and column. Functions and procedures with bodies that are not dollar-quoted are now ignored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Schema files are now split into statements using JSqlParser's own lexer, and each statement is parsed on its own. A statement the parser cannot read no longer fails the whole file. Real migration histories and
pg_dump --schema-onlysnapshots that containDOblocks,DROP TYPE,COMMENT ON TYPE,SET search_path TO a, b, identity columns orNOT VALIDconstraints now load.Changes
$$ ... $$bodies do not split. A tagged dollar-quoted body such as$body$ ... $body$or$fn$BEGIN ... END$fn$ends at the next occurrence of its own delimiter. A body that is never closed fails with its line and column.\restrictand\unrestrictlines that recentpg_dumpreleases write, are skipped, and every reported line and column stays a position in the original file.CREATE/ALTER/DROP TABLEorCREATE/ALTER TYPE. Such an unreadable table or type statement is rejected with the parser's reason at the file line and column of the unexpected token, for exampleEncountered unexpected token: "DATA" at line 3, column 41.ALTER TABLEis ignored, without resolving its table, when each of its top-level actions isADD CONSTRAINT <name>,ADD CHECK/UNIQUE/EXCLUDE/PRIMARY KEY/FOREIGN KEY, orALTER [COLUMN] <name> ADD GENERATED. This covers the identity formpg_dumpwrites, as well asEXCLUDE,DEFERRABLE INITIALLY DEFERRED,USING INDEX,NOT VALIDand unnamedCHECKconstraints. Any other unreadableALTER TABLE, such asALTER COLUMN ... SET DATA TYPE, is still rejected.RETURNare now ignored like dollar-quoted ones, and the statements after them are applied.DROP TYPEis ignored, so a modeled enum and its columns stay modeled.E'...'strings.Scope and non-goals
ALTER TABLEandALTER TYPEactions that are still rejected, such asSET DEFAULTandOWNER TO.DOblocks and function bodies is still not modeled, andDROP TYPE ... CASCADEdoes not remove columns.LIKEandPARTITION OFtables, andCOPYdata are unchanged.E'it\'s'mis-lex is documented, not fixed.