Tighten sqlite3 parser reference facade#138
Open
mmkal wants to merge 4 commits into
Open
Conversation
commit: |
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
This stacked PR extends the parser-backed reference facade from PR #111 so partial-index
whereexpressions are analyzed bysqlite3-parserinstead of the planner token-scanning raw SQL.The net effect is narrower direct drop-column planning: function names and collation names inside a partial index no longer look like dropped-column references, while real column references in the
whereexpression still force the conservative table rebuild path.Base PR: #111 (
issue-110-sqlite3-parser-schemadiff).Before / after
Before, the planner used
sqlMentionsIdentifier(index.where, column.name), so these valid drops could be misread as partial-index dependencies:Those now stay on the direct path:
A true reference still rebuilds the table:
Implementation
indexWhereReferenceFactsandindexWhereReferencesDroppedColumnstopackages/sqlfu/src/schemadiff/sqlite/references.ts.sqlite3-parserimports insidereferences.ts.plan.tspartial-index token scan with the sqlfu-owned facade helper.drop-column.sqlschemadiff fixtures forlower(x),collate nocase, andwhere y > 0.Tests
pnpm --filter sqlfu exec vitest run test/schemadiff/fixtures.test.tspnpm --filter sqlfu typecheckpnpm exec oxfmt --check packages/sqlfu/src/schemadiff/sqlite/references.ts packages/sqlfu/src/schemadiff/sqlite/plan.tsNote
Medium Risk
Changes SQLite drop-column vs rebuild decisions in schemadiff; incorrect reference extraction could pick the wrong migration path, though behavior is covered by fixture tests.
Overview
Partial-index WHERE clauses are now analyzed through the sqlite3-parser facade in
references.tsinstead of token-scanningindex.wherein the planner. DirectALTER TABLE … DROP COLUMNeligibility usesindexWhereReferencesDroppedColumns, which parsesCreateIndexStmtand only treats real column references as blockers.Behavior change: dropping columns named like SQL builtins (e.g.
lower,nocase) no longer misfires when those names appear only as a function or COLLATE in the partial index predicate; a genuine reference such aswhere y > 0still forces a table rebuild. New schemadiff fixtures document those cases.Reviewed by Cursor Bugbot for commit b62ca54. Bugbot is set up for automated code reviews on this repo. Configure here.