Skip to content

Commit 60f07c3

Browse files
fix(migrations): sort migrations as ints not strings
Fixes #1185
1 parent 04da1b6 commit 60f07c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

migrate/migration.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"io/fs"
1010
"sort"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -291,12 +292,22 @@ func WithNopMigration() MigrationOption {
291292

292293
func sortAsc(ms MigrationSlice) {
293294
sort.Slice(ms, func(i, j int) bool {
295+
ni, ei := strconv.ParseInt(ms[i].Name, 10, 64)
296+
nj, ej := strconv.ParseInt(ms[j].Name, 10, 64)
297+
if ei == nil && ej == nil && ni != nj {
298+
return ni < nj
299+
}
294300
return ms[i].Name < ms[j].Name
295301
})
296302
}
297303

298304
func sortDesc(ms MigrationSlice) {
299305
sort.Slice(ms, func(i, j int) bool {
306+
ni, ei := strconv.ParseInt(ms[i].Name, 10, 64)
307+
nj, ej := strconv.ParseInt(ms[j].Name, 10, 64)
308+
if ei == nil && ej == nil && ni != nj {
309+
return ni > nj
310+
}
300311
return ms[i].Name > ms[j].Name
301312
})
302313
}

0 commit comments

Comments
 (0)