Skip to content

fix: resolve migration timestamp collisions#30

Open
MerlinTheWhiz wants to merge 1 commit into
LabsCrypt:mainfrom
MerlinTheWhiz:fix/migration-timestamp-collisions
Open

fix: resolve migration timestamp collisions#30
MerlinTheWhiz wants to merge 1 commit into
LabsCrypt:mainfrom
MerlinTheWhiz:fix/migration-timestamp-collisions

Conversation

@MerlinTheWhiz

@MerlinTheWhiz MerlinTheWhiz commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Closes #22

Summary

Problem

Four pairs of migration files shared identical timestamp prefixes, making their apply order non-deterministic:

Collision Files
1777000000007 loan-events-composite-indexes, unique-loan-status-events
1778000000008 quarantine-events, transaction-submissions
1786000000016 ensure-loan-events-loan-id-index, webhook-max-attempts
1788000000018 add-loan-events-missing-indexes, unified-contract-events

The 1788000000018 pair was most critical: add-loan-events-missing-indexes creates indexes on loan_events while unified-contract-events renames that table to contract_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:

Before After
1777000000007_unique-loan-status-events.js 1777000000008_unique-loan-status-events.js
1778000000008_transaction-submissions.js 1778000000009_transaction-submissions.js
1786000000016_webhook-max-attempts.js 1786000000017_webhook-max-attempts.js
1788000000018_unified-contract-events.js 1788000000019_unified-contract-events.js

All 27 timestamps are now unique and strictly increasing. The critical pair is correctly ordered — add-loan-events-missing-indexes (1788000000018) runs before unified-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 pgmigrations on existing databases after the rename.

Verification

  • All timestamps unique and strictly increasing
  • Existing DB + renamed files: node-pg-migrate correctly blocks with order-check error
  • Running the provided SQL to sync pgmigrations then allows migrate:up to succeed
  • Documented convention to prevent future timestamp collisions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Four pairs of migrations share identical timestamps, making apply order non-deterministic

1 participant