Skip to content

fix(cli): order migrations by version - #6038

Merged
avallete merged 3 commits into
supabase:developfrom
7ttp:fix/ts-migration-version-ordering-6036
Aug 3, 2026
Merged

fix(cli): order migrations by version#6038
avallete merged 3 commits into
supabase:developfrom
7ttp:fix/ts-migration-version-ordering-6036

Conversation

@7ttp

@7ttp 7ttp commented Aug 3, 2026

Copy link
Copy Markdown
Member

TL;DR

Fixing db push failing with Remote migration versions not found in local migrations directory
for a version that's sitting right there on disk, which happened because local files arrive in name order while schema_migrations comes back in version order, and
those two disagree whenever one version is a string prefix of another (1 vs 10, or 20260420 vs 20260420010000): 10_b.sql sorts before 1_a.sql ('0' < '_'),
so the two-pointer merge desynchronises and reports an already-applied version as missing. migration up walks the same merge, and migration repair --status reverted is no way out, the versions just come back as ErrMissingRemote...

sorted now by ordering local paths by version before the walk:
a new legacySortMigrationPathsByVersion called from both legacyFindPendingMigrations implementations,
rather than from legacyListLocalMigrations where the name ordering originates that list also feeds the pgdelta cache hash, so reordering it there would drift the cache key. TS shell only, since that's the user-facing path today via legacy....

--include-all needed the same treatment:
it slices the local list at remoteCount + diff.length, so with diff now version-ordered it has to index the version-ordered list too. Left name-ordered it would re-apply an already-applied migration and silently skip a pending one (1,2,20 with 2 applied → [1, 2] instead of [1, 20]).

Refs

@7ttp
7ttp requested a review from a team as a code owner August 3, 2026 08:54
@7ttp 7ttp self-assigned this Aug 3, 2026
@7ttp 7ttp added the migration label Aug 3, 2026
@avallete
avallete added this pull request to the merge queue Aug 3, 2026
Merged via the queue into supabase:develop with commit c2ec9f5 Aug 3, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db push fails: 'Remote migration versions not found' when 8-digit and 14-digit migration timestamps share the same prefix

2 participants