fix(db): do not panic when undo migration SQL is missing - #4103
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(db): do not panic when undo migration SQL is missing#4103cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
Commit
0bd3589achangedTryRollbackMigrationto callgetVersionSQL(..., ignoreErrors=false). Only ~31 of ~98 migrations ship a.err.sqlundo script. For any migration without one, rollback now panics instead of logging a warning and skipping.Concrete triggers:
db.MigratecallsTryRollbackMigrationwhenApplyMigrationfails. If the failing migration has no.err.sql(most do not), the Semaphore process crashes instead of returning the migration error.db.Rollbackiterates applied migrations and callsTryRollbackMigrationfor each. Rolling back past any version without undo SQL panics the process.Root cause
getVersionSQLpanics on a missing embedded file whenignoreErrorsisfalse. The change was likely intended to surface missing undo SQL forv2.20.1, butTryRollbackMigrationis invoked for all migrations during rollback — not only those with undo scripts.Fix
ignoreErrors=trueinTryRollbackMigrationso missing.err.sqlfiles are handled gracefully (warn + skip), as before0bd3589a.v2.20.1.err.sqlundo script added in that commit.ignoreErrorsbehavior.Validation
go test ./db/sql -run TestGetVersionSQL -count=1— pass