fix: resolve migration timestamp collisions#30
Open
MerlinTheWhiz wants to merge 1 commit into
Open
Conversation
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 #22
Summary
Problem
Four pairs of migration files shared identical timestamp prefixes, making their apply order non-deterministic:
1777000000007loan-events-composite-indexes,unique-loan-status-events1778000000008quarantine-events,transaction-submissions1786000000016ensure-loan-events-loan-id-index,webhook-max-attempts1788000000018add-loan-events-missing-indexes,unified-contract-eventsThe
1788000000018pair was most critical:add-loan-events-missing-indexescreates indexes onloan_eventswhileunified-contract-eventsrenames that table tocontract_events. If they ran in the wrong order, the index creation would fail.Changes
Renamed one file per colliding pair to a unique, strictly-increasing timestamp:
1777000000007_unique-loan-status-events.js1777000000008_unique-loan-status-events.js1778000000008_transaction-submissions.js1778000000009_transaction-submissions.js1786000000016_webhook-max-attempts.js1786000000017_webhook-max-attempts.js1788000000018_unified-contract-events.js1788000000019_unified-contract-events.jsAll 27 timestamps are now unique and strictly increasing. The critical pair is correctly ordered —
add-loan-events-missing-indexes(1788000000018) runs beforeunified-contract-events(1788000000019).README — updated the core migrations table, added a migration naming convention section to prevent future collisions, and documented the exact SQL to fix
pgmigrationson existing databases after the rename.Verification
node-pg-migratecorrectly blocks with order-check errorpgmigrationsthen allowsmigrate:upto succeed