Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(db): do not panic when undo migration SQL is missing - #4103

Draft
cursor[bot] wants to merge 1 commit into
developfrom
cursor/critical-bug-investigation-16d8
Draft

fix(db): do not panic when undo migration SQL is missing#4103
cursor[bot] wants to merge 1 commit into
developfrom
cursor/critical-bug-investigation-16d8

Conversation

@cursor

@cursor cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bug and impact

Commit 0bd3589a changed TryRollbackMigration to call getVersionSQL(..., ignoreErrors=false). Only ~31 of ~98 migrations ship a .err.sql undo script. For any migration without one, rollback now panics instead of logging a warning and skipping.

Concrete triggers:

  1. Failed migration auto-rollbackdb.Migrate calls TryRollbackMigration when ApplyMigration fails. If the failing migration has no .err.sql (most do not), the Semaphore process crashes instead of returning the migration error.
  2. Manual downgradedb.Rollback iterates applied migrations and calls TryRollbackMigration for each. Rolling back past any version without undo SQL panics the process.

Root cause

getVersionSQL panics on a missing embedded file when ignoreErrors is false. The change was likely intended to surface missing undo SQL for v2.20.1, but TryRollbackMigration is invoked for all migrations during rollback — not only those with undo scripts.

Fix

  • Restore ignoreErrors=true in TryRollbackMigration so missing .err.sql files are handled gracefully (warn + skip), as before 0bd3589a.
  • Keep the new v2.20.1.err.sql undo script added in that commit.
  • Add unit tests locking in the ignoreErrors behavior.

Validation

  • go test ./db/sql -run TestGetVersionSQL -count=1 — pass
Open in Web View Automation 

Commit 0bd3589 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant