fix: bump and retry goose create on duplicate migration versions - #1118
Open
cestercian wants to merge 1 commit into
Open
fix: bump and retry goose create on duplicate migration versions#1118cestercian wants to merge 1 commit into
cestercian wants to merge 1 commit into
Conversation
Detect version collisions during create and retry the O_EXCL write with a bumped version so different names cannot share a timestamp or sequential version. Exact filename collisions still return os.ErrExist. CollectMigrations now errors on duplicates instead of panicking in Migrations.Less. Fixes pressly#1116
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.
Bug
goose createcan write two migrations with different names but the same version.20060102150405, so lateruppanics inMigrations.Less(migrate.go) with a duplicate version. The provider path already returns a proper error.-s): scan forlast.Version+1then create is TOCTOU. Concurrent creates collide; create itself can panic when the dir scan hits the duplicates.O_EXCLfor the filename, but that does not protect version uniqueness across different names.Fix
Option 2 from #1116:
O_EXCLcreate, detect when another file already owns that version.max+1) and retryO_EXCL.os.ErrExist(keeps fix: return clear error when migration file already exists #1104).collectMigrationsFS, so existing duplicate versions cannot panic create.timestampFormatis unchanged (no sub-second versions).CollectMigrationsnow returns an error for duplicate versions instead of panicking inMigrations.Less, matchingprovider_collect.go.Tests
TestCreateDuplicateFilestill expectsos.ErrExist.Fixes #1116
Drafted with Cursor; human-reviewed before opening.