Skip to content

Commit 754bfd1

Browse files
bug(migrations): Sort migrations as ints not strings
Fixes #1185
1 parent 04da1b6 commit 754bfd1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

migrate/migration.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,22 @@ func WithNopMigration() MigrationOption {
291291

292292
func sortAsc(ms MigrationSlice) {
293293
sort.Slice(ms, func(i, j int) bool {
294+
ni, ei := strconv.ParseInt(ms[i].Name, 10, 64)
295+
nj, ej := strconv.ParseInt(ms[j].Name, 10, 64)
296+
if ei == nil && ej == nil && ni != nj {
297+
return ni < nj
298+
}
294299
return ms[i].Name < ms[j].Name
295300
})
296301
}
297302

298303
func sortDesc(ms MigrationSlice) {
299304
sort.Slice(ms, func(i, j int) bool {
305+
ni, ei := strconv.ParseInt(ms[i].Name, 10, 64)
306+
nj, ej := strconv.ParseInt(ms[j].Name, 10, 64)
307+
if ei == nil && ej == nil && ni != nj {
308+
return ni > nj
309+
}
300310
return ms[i].Name > ms[j].Name
301311
})
302312
}

0 commit comments

Comments
 (0)