From b6f9d0c1df40e2759cfa78a1142d747e507f4b67 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 11:03:04 +0000 Subject: [PATCH] fix(db): do not panic when undo migration SQL is missing Commit 0bd3589a changed TryRollbackMigration to pass ignoreErrors=false, which panics for the ~70 migrations without a .err.sql file. That crashes the process during failed-migration auto-rollback and manual downgrade. Restore ignoreErrors=true while keeping the new v2.20.1.err.sql undo script. Co-authored-by: Denis Gukov --- db/sql/migration.go | 3 ++- db/sql/migration_test.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 db/sql/migration_test.go diff --git a/db/sql/migration.go b/db/sql/migration.go index 0f5e86ee0f..e14da8a317 100644 --- a/db/sql/migration.go +++ b/db/sql/migration.go @@ -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) diff --git a/db/sql/migration_test.go b/db/sql/migration_test.go new file mode 100644 index 0000000000..a7d1169cde --- /dev/null +++ b/db/sql/migration_test.go @@ -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) + }) +}