fix(cli): order migrations by version - #6038
Merged
avallete merged 3 commits intoAug 3, 2026
Merged
Conversation
avallete
approved these changes
Aug 3, 2026
This was referenced Aug 3, 2026
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.
TL;DR
Fixing
db pushfailing withRemote migration versions not found in local migrations directoryfor a version that's sitting right there on disk, which happened because local files arrive in name order while
schema_migrationscomes back in version order, andthose two disagree whenever one version is a string prefix of another (
1vs10, or20260420vs20260420010000):10_b.sqlsorts before1_a.sql('0'<'_'),so the two-pointer merge desynchronises and reports an already-applied version as missing.
migration upwalks the same merge, andmigration repair --status revertedis no way out, the versions just come back asErrMissingRemote...sorted now by ordering local paths by version before the walk:
a new
legacySortMigrationPathsByVersioncalled from bothlegacyFindPendingMigrationsimplementations,rather than from
legacyListLocalMigrationswhere the name ordering originates that list also feeds thepgdeltacache hash, so reordering it there would drift the cache key. TS shell only, since that's the user-facing path today via legacy....--include-allneeded the same treatment:it slices the local list at
remoteCount + diff.length, so withdiffnow 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,20with2applied →[1, 2]instead of[1, 20]).Refs