fix(#255): migrate emits constraint/index drops before drop-column - #257
Merged
Conversation
…erenced-column drops apply Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLoJkFSyoticveo5ehMUAr
…x cascade class) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLoJkFSyoticveo5ehMUAr
…only) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLoJkFSyoticveo5ehMUAr
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.
Closes #255.
npm-only (
migrate-ts). The SQL emitter'sSTAGE_ORDERranDROP COLUMN(stage 2) beforeDROP CONSTRAINT(FK/check, stage 5) andDROP INDEX(stage 4), so dropping a column that a still-present foreign key referenced — or that a still-present index backed — produced an un-appliable migration (cannot drop column … because other objects depend on it). Root cause: constraint/index drops shared a stage with their adds but need the opposite order vs column mutation.Fix (both
emit/postgres.ts+emit/sqlite.ts): hoist all drops ahead of column mutation —drop-fk/drop-checkat stage 1,drop-indexat 1.5 (a foreign key depends on the unique/PK index backing its target, so the FK must drop before that index), columns at 2; adds (add-fk/add-check/add-index) stay late. Only those three stage keys moved; every other stage is unchanged.Validated against real Postgres 16 (Testcontainers): reproduced the exact apply errors pre-fix, applies cleanly + re-diff-empty post-fix, including the combined FK + backing-index + column-drop scenario. New
pg-drop-fk-before-drop-column.test.ts(emit→apply→introspect→re-diff-empty) + unit order-assertions for both dialects.Byte-identity: any migration with none of
drop-fk/drop-check/drop-indexis byte-identical (only those keys' positions changed; stable sort). A migration combining one of those drops with a column change now emits the corrected order — CHANGELOG flags this so adopters re-review un-applied migration files.Reviewed (senior, opus): ready to merge, no Critical/Important; all ordering invariants, byte-identity, real-engine genuineness, down-path, and sqlite recreate-and-copy interaction verified.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HLoJkFSyoticveo5ehMUAr