Repository navigation
Replay plain-numbered migrations in number order - #64
Open
chiragjangiir wants to merge 1 commit into
Open
chiragjangiir wants to merge 1 commit into
chiragjangiir wants to merge 1 commit into
Conversation
Lexicographic order ran 10_drop_legacy.sql before 2_add_legacy.sql, keeping the column the later migration drops. Sort by the leading number, then the rest; timestamped names keep their order.
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 #57.
What happens today
_migration_filesreturns the files insource.list_filesorder, which is plain lexicographic, so a plain-numbered folder replays10_drop_legacy.sqlbefore2_add_legacy.sql. The drop then hits a column that does not exist yet (counted inunknown), and the laterADD COLUMNputs it back, so the extracted model keeps a column the real database no longer has.Fix
migration_sort_keyorders a file by the numbers in its base name — the split on digit runs keeps text parts compared as lowercased text — so1_,2_,10_replay in number order while timestamped names (Supabase, dbmate) keep the order they already had.Tests
Ordering.test_plain_numbered_migrations_run_in_number_order:1_init.sqlcreatesusers(id),2_add_legacy.sqladdslegacy,10_drop_legacy.sqldrops it; asserts the model has nolegacycolumn.Ordering.test_timestamped_names_keep_their_order: timestamped names still create then drop.Verified with
python3.12 -m unittest tests.test_postgres: withcore/extractors/postgres.pystashed (the old sorting) the first test fails with'legacy' unexpectedly found in {...}and the second passes; with the change, all 32 tests in the module pass.I did not run the full suite or the live PostgreSQL check (
PGBIN) — the change is confined to file ordering. The changelog has an entry under[Unreleased]→### Fixed.