Repository navigation
fix(parser): stop dropping columns named like constraint keywords - #39
Merged
Peter-L-SVK merged 1 commit intoOct 10, 2026
Conversation
The constraint check in _parse_column_line_robust used str.startswith() against a tuple of keywords. That matched any column whose name merely began with one of them, so unique_code, constraint_name, check_flag and excluded_at were all treated as table constraints and silently dropped. The Schema Designer then drew a table with fewer columns than the SQL declares and gave no warning. The keywords are now matched with a word boundary so PRIMARY KEY (a, b), UNIQUE (email) and CONSTRAINT ... CHECK (...) are still skipped while prefixed column names parse as columns. Adds two tests. One fails on the old code with unique_code and constraint_name missing from the column list. The other pins down that table-level constraints are still skipped.
Contributor
Author
|
no ai btw |
Peter-L-SVK
self-requested a review
October 10, 2026 15:19
Peter-L-SVK
removed their request for review
October 10, 2026 15:20
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.
The constraint check in
_parse_column_line_robustusedstr.startswith()against a tuple of keywords.startswithmatches prefixes, so any column whose name merely began with one of the keywords got treated as a table constraint and dropped.This table loses three columns silently:
Parsing it returns only
id. The Schema Designer draws the table with a third of its columns missing and shows no error, so it looks like the SQL only ever declared one column.The keywords are now matched with a word boundary.
PRIMARY KEY (a, b),UNIQUE (email)andCONSTRAINT chk_len CHECK (...)are still skipped, and prefixed column names parse as columns.Two tests added:
unique_codeandconstraint_namemissing from the resultVerified locally with the four test files that do not need a live database:
black --checkandflake8are clean on both changed files. mypy reports no issues onschema_parser.py. I could not run the database backed tests because there is no PostgreSQL server on my machine at this time.