fix(Migrator): harden DDL matching and error reporting - #246
Open
h2zi wants to merge 2 commits into
Open
Conversation
Five related fixes to how the migrator matches DDL and reports failures: - GetTables: exclude sqlite_* internal tables; sqlite_sequence appeared in the list as soon as any table used AUTOINCREMENT. - HasConstraint: match the exact constraint name via the parsed DDL and compileConstraintRegexp instead of LIKE substrings, which matched prefixes and names embedded in other text. - DropColumn: report an error when the column is not present in the DDL; removeColumn returned false silently and the table was rebuilt unchanged. - removeColumn: match unquoted column names; the regexp required a quote or space before the name, so columns of hand-written DDL like "CREATE TABLE t (id integer, name text)" were never matched. - getRawDDL: report "table not found" instead of passing an empty string to parseDDL, which surfaced as a confusing "invalid DDL". - uniqueRegexp: recognize lowercase and no-space table-level unique(...) constraints; every other DDL regexp is already case-insensitive.
This was referenced Jul 31, 2026
There was a problem hiding this comment.
Pull request overview
This PR hardens the SQLite migrator’s DDL parsing/matching logic to avoid false positives and silent no-ops, and improves error reporting around missing tables/columns.
Changes:
- Filter
GetTables()results to excludesqlite_*internal tables. - Rework
HasConstraint()to parse table DDL and match exact constraint names; makeDropColumn()error when a column is not found in the parsed DDL; improvegetRawDDL()“table not found” reporting. - Extend DDL parsing to recognize lowercase / no-space table-level
unique(...)constraints; loosen column-removal matching to handle unquoted column definitions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| migrator.go | Updates table listing, constraint detection, drop-column behavior, and DDL retrieval error handling. |
| migrator_test.go | Adds tests covering internal-table exclusion, constraint-name matching, and drop-column failure modes. |
| ddlmod.go | Adjusts DDL regexes for UNIQUE parsing and improves column removal matching for unquoted DDL. |
| ddlmod_test.go | Adds a regression test for lowercase table-level unique(...) parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: the LIKE patterns that HasConstraint used before explicitly handled [name], which compileConstraintRegexp did not. It now accepts backquotes, double quotes, single quotes, brackets or no quoting, covered by TestConstraintNameQuoting across all forms. Also fail TestParseDDL_LowercaseUnique when the column is not parsed at all.
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.
A batch of small, related fixes to how the migrator matches DDL and reports failures. Each is independently small; grouped because they share the theme (and the tests).
sqlite_*internal tables —sqlite_sequenceappeared in the list as soon as any table usedAUTOINCREMENT.compileConstraintRegexpinstead of LIKE substrings, which matched prefixes (age_posmatchedage_positive).removeColumnreturnedfalsesilently and the table was rebuilt unchanged, so callers saw success without any effect.CREATE TABLE t (id integer, name text)were never matched (same silent no-op as above).table not foundinstead of passing an empty string toparseDDL, which surfaced as a confusinginvalid DDL.unique(...)constraints; every other DDL regexp is already case-insensitive. Written to not mistake a column nameduniqueidfor a constraint (requires the parenthesized column list).Tests:
TestGetTablesExcludesInternal,TestConstraintAndColumnMatching,TestParseDDL_LowercaseUnique.No dependency on the other open PRs — merges cleanly in any order.
🤖 Generated with Claude Code
Merge order (this batch: #241 → #242 → #243 → #244 → #245 → #246, plus #234 from the previous batch): all seven are functionally independent and merge cleanly in any order. Several append tests to the same test files, so whichever merges later may show a trivial append-only conflict in
migrator_test.go/ddlmod_test.go— I'll rebase the remaining ones promptly after each merge, as before.