Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion db/sql/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ func (d *SqlDb) TryRollbackMigration(version db.Migration) {
return
}

queries := getVersionSQL(d.GetDialect(), getVersionErrPath(version), false)
// Most migrations have no undo SQL; a missing .err.sql file must not panic.
queries := getVersionSQL(d.GetDialect(), getVersionErrPath(version), true)

for _, query := range queries {
fmt.Printf(" [ROLLBACK] > %v\n", query)
Expand Down
20 changes: 20 additions & 0 deletions db/sql/migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sql

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetVersionSQL_MissingErrFileWithIgnoreErrors(t *testing.T) {
assert.NotPanics(t, func() {
queries := getVersionSQL("sqlite", "v9999.9.9.err.sql", true)
assert.Nil(t, queries)
})
}

func TestGetVersionSQL_MissingErrFileWithoutIgnoreErrorsPanics(t *testing.T) {
assert.Panics(t, func() {
getVersionSQL("sqlite", "v9999.9.9.err.sql", false)
})
}
Loading