Repository navigation
fix(seedling-gen): Keep string and comment text out of SQL and Atlas schema structure - #103
Merged
Merged
Conversation
…resolved foreign keys The columns pattern also matched inside ref_columns, so a foreign_key block that listed ref_columns first took the referenced column as its local column, the real FK column was never marked, and the generated blueprint silently lost the relation. Attribute patterns now match whole names only, and a foreign_key block without columns or ref_columns, or with a local column the table does not declare, is reported as an error instead of being skipped.
…ructure Brace matching toggled on every double quote, so an escaped quote such as \" in a comment attribute flipped the string state and a valid schema failed with "unclosed brace"; attribute patterns could also match text inside strings, such as a column comment containing "null = true". The parser now builds one offset-preserving masked copy of the input in which comments, including block comments, and string contents are blanked with escapes honored. Structure is matched on the masked copy while block names are still read from the original text.
… structure CREATE TABLE statements were searched for in raw text, so a string such as SELECT 'CREATE TABLE ghosts (...)' produced a table that does not exist, and constraint detection masked only single-quoted strings, so DEFAULT $$NOT NULL$$ marked a nullable column NOT NULL. A single lexer now builds an offset-preserving masked copy of the schema that blanks comments, string literals, and quoted identifier contents, following the dialect: dollar quotes and E'...' strings for PostgreSQL and auto, backslash escapes for MySQL. Table discovery, parenthesis matching, item splitting, and constraint detection all run on that copy, replacing four separate quote-tracking scanners.
A column that was both primary key and foreign key, such as user_id INTEGER PRIMARY KEY REFERENCES users(id), was read as nullable because only an explicit NOT NULL counted, so the relation became optional and the shared-key parent was never generated. Nullability is now settled after every constraint is read: a primary key implies NOT NULL in standard SQL, while SQLite keeps its own rule and implies it only for the INTEGER PRIMARY KEY rowid alias and WITHOUT ROWID tables. Each foreign key's required flag is computed from the final column state.
…ings The foreign key check accepted ref_columns that named only a table, a different number of columns than columns, or columns on two tables; each ref_columns entry is now resolved on its own, a bare column.x references the current table, and those mismatches are reported. Attribute names also no longer match after a hyphen, which HCL allows in identifiers, so allow-null or sql-type are not read as null or type. Heredoc strings (<<EOT and <<-EOT) are masked up to their closing marker like quoted strings.
…ents, and descending SQLite keys The SQL lexer missed comment forms that hide schema text: MySQL reads # as a line comment, and PostgreSQL block comments nest, so text after an inner */ was treated as structure. MySQL now masks # comments, auto masks a # that starts a line, and PostgreSQL and auto nest block comments. An inline INTEGER PRIMARY KEY DESC is not a rowid alias in SQLite, so it no longer implies NOT NULL there.
…foreign keys Explain that --dialect now selects string quoting and primary key nullability rather than serving only as a validation hint, that text inside strings and comments never becomes schema structure, and that the atlas subcommand rejects foreign_key blocks it cannot resolve.
Code Metrics Report
Details | | main (9a2b1f6) | #103 (2657649) | +/- |
|---------------------|----------------|----------------|-------|
- | Coverage | 86.9% | 86.6% | -0.3% |
| Files | 59 | 59 | 0 |
| Lines | 4791 | 4766 | -25 |
- | Covered | 4165 | 4130 | -35 |
+ | Code to Test Ratio | 1:1.0 | 1:1.0 | +0.0 |
| Code | 17787 | 17806 | +19 |
+ | Test | 17916 | 18089 | +173 |
- | Test Execution Time | 1m11s | 1m34s | +23s |Code coverage of files in pull request scope (96.2% → 94.0%, patch 96.1%)
Reported by octocov |
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
foreign_keyblocks are reported instead of silently dropping the relation--dialectnow selects string/comment syntax (PostgreSQL dollar quotes,E'...', nested comments; MySQL backslash escapes and#comments)Changes
columnsno longer matches insideref_columns, so attribute order does not drop the FKforeign_keyblock withoutcolumns/ref_columnsor with an undeclared local column is an error\"no longer break brace matching, and attribute patterns ignore text inside strings and comments, including block commentsCREATE TABLEinside a string or$$NOT NULL$$in a DEFAULT is no longer read as schemaINTEGER PRIMARY KEYrowid alias andWITHOUT ROWIDtablesref_columnsentry is resolved, with mismatched counts or multiple tables reported; hyphenated names and<<EOTheredocs are handled#comments, nested PostgreSQL block comments, and SQLiteINTEGER PRIMARY KEY DESCfollow their dialect's rules--dialectflag help