Repository navigation
Conversation
nextSeqVersion took the sequence prefix from the last element of the filepath.Glob result, which is sorted lexically. Once a project has both single- and multi-digit versions (e.g. 9_ and 10_), '9_...' sorts after '10_...', so 'migrate create -seq' derived the next version from 9 and produced a duplicate version error. Scan every match and keep the numeric maximum instead. Malformed-filename and parse errors are still reported per element, so behaviour is unchanged for well-formed inputs. Fixes golang-migrate#1109
chj2dctmcr-debug
approved these changes
Sep 20, 2026
Author
|
Hi maintainers, the only failing check on this PR is the Go 1.25.x test job. The failures are Docker containers timing out on startup ( |
This branch has not been deployed
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.
What
Make
migrate create -seqderive the next version from the numerically highestexisting migration instead of the lexically last filename.
Why / evidence
nextSeqVersion(internal/cli/commands.go) read the sequence prefix frommatches[len(matches)-1].filepath.Globreturns paths in lexical order, soonce a project has both single- and multi-digit versions the last entry is
9_*(it sorts after10_*,11_*, ...). The next version was then computedas
9 + 1 = 10, colliding with the existing10_*files.Reproduced with the scenario from #1109: a migrations dir containing
0_..11_pairs, then
migrate create -dir ./migrations -seq -digits 2 -ext sql foobar=>
error: duplicate migration version: 10.Change
In
nextSeqVersion, iterate over every glob match, parse each numeric prefix,and keep the maximum; next version is
max + 1. Per-file malformed-name andParseUinterrors are unchanged, so behaviour for well-formed input isidentical. One function, ~9 lines.
Verified
Multi digit lexical order(
[]string{"0_x","10_x","11_x","1_x","2_x","9_x"}->000012). Fails on thecurrent code (
got 000010), passes with the fix.go test ./internal/cli/-> okgofmt -l internal/cli/clean;go vet ./internal/cli/clean.Fixes #1109