Skip to content

fix(migrations): unbreak main, and stop two sessions sharing a version number - #779

Merged
catomean merged 1 commit into
mainfrom
fix/migration-version-collision
Aug 26, 2026
Merged

fix(migrations): unbreak main, and stop two sessions sharing a version number#779
catomean merged 1 commit into
mainfrom
fix/migration-version-collision

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

main is red and CD has stopped deploying for the whole repo.

ERROR: duplicate key value violates unique constraint "schema_migrations_pkey"
Key (version)=(20260826180000) already exists.

Cause

Supabase keys its ledger on the numeric prefix of the filename
(supabase_migrations.schema_migrations.version, a PRIMARY KEY), not on the
whole name. Two sessions working in parallel each timestamped a migration
20260826180000:

  • 20260826180000_mention_queue_all_mentions.sql
  • 20260826180000_resolve_username_history_rpc.sql

To the ledger those are one migration, so the replay aborts.

git cannot catch this. Neither file conflicts with the other — different
names, different contents, no overlapping lines. Only the ledger notices, and by
then it is on main, where it blocks the deploy carrying the fix each session was
waiting on.

Fix

Renamed mine to 20260826181500. Nothing else about it changes; the collision
is entirely in the filename.

Closing the class

"Pick a unique timestamp" is exactly the kind of instruction that works until
two people are typing at once. scripts/check-migration-versions.mjs fails when
any two migrations share a version prefix and runs inside verify, so a
collision costs one red PR check instead of a blocked pipeline:

✗ migration version collision — supabase_migrations.schema_migrations.version is a PRIMARY KEY,
  so these files are the same migration to the ledger and a replay will abort:

  20260826180000:
    20260826180000_mention_queue_all_mentions.sql
    20260826180000_zz_reintroduced_collision.sql

  Fix: bump one filename to an unused timestamp. Nothing else needs to change.

Verified by reintroducing a duplicate and watching it name both files, then
passing on a clean tree.

npm run verify green; 2385 tests pass.

…n number

main is red and CD has stopped deploying for the whole repo. Migration
Replay aborts with:

  ERROR: duplicate key value violates unique constraint
         "schema_migrations_pkey"
  Key (version)=(20260826180000) already exists.

Supabase keys its ledger on the numeric PREFIX of the filename
(supabase_migrations.schema_migrations.version, a PRIMARY KEY), not on
the whole name. Two sessions working in parallel each timestamped a
migration 20260826180000 — mention_queue_all_mentions and
resolve_username_history_rpc — so to the ledger they are one migration,
and replaying them dies.

git cannot catch this. Neither file conflicts with the other: different
names, different contents, no overlapping lines. Only the ledger notices,
and by then it is on main, where it blocks the deploy carrying the fix
each session was waiting on.

Renamed mine to 20260826181500. Nothing else about it changes; the
collision is entirely in the filename.

Then closed the class, because "pick a unique timestamp" is exactly the
kind of instruction that works until two people are typing at once:
scripts/check-migration-versions.mjs fails when any two migrations share
a version prefix, and it runs inside `verify`, so a collision costs one
red PR check instead of a blocked pipeline. Verified by reintroducing a
duplicate and watching it name both files, then passing on a clean tree.

npm run verify green; 2385 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@catomean
catomean merged commit 95875c4 into main Aug 26, 2026
6 checks passed
@catomean
catomean deleted the fix/migration-version-collision branch August 26, 2026 21:46
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.

1 participant