fix(migration): stop a half-applied startup migration from committing silently - #6182
Open
n0ctal wants to merge 1 commit into
Open
fix(migration): stop a half-applied startup migration from committing silently#6182n0ctal wants to merge 1 commit into
n0ctal wants to merge 1 commit into
Conversation
n0ctal
force-pushed
the
upstream-migration-commit-errors
branch
from
August 8, 2026 02:10
fdaf2e7 to
8ce4d2f
Compare
n0ctal
force-pushed
the
upstream-migration-commit-errors
branch
from
August 8, 2026 02:23
8ce4d2f to
4e4d934
Compare
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.
Summary
Return and check the error from
MigrationRequirements, stop inner:=assignments from shadowing it, and propagate commit failures in both the startup migration andOutboundService.AddTraffic.Why
MigrationRequirementswraps the startup migration in a transaction whose deferred handler commits whenerr == nil. Two separate things defeat that guard:Shadowing. Several steps inside the loop declare their own error with
:=—modifiedSettings, err := json.MarshalIndent(...),modelClients, err := s.GetClients(...). A failure there returns early while the outererris still nil, so the deferred handler commits a migration that stopped halfway.Discarded commit error.
tx.Commit()'s result was dropped. A commit that failed was indistinguishable from one that succeeded.MigrateDBthen ignored the outcome entirely, so a startup migration could fail, partially commit, and leave no trace. On the next start the panel runs against a schema state nobody intended, and the original failure is unrecoverable from the logs.OutboundService.AddTraffichad the same discarded-commit shape in its own hand-rolled transaction.Scope
MigrationRequirementsreturnserror; the inner assignments use the named return instead of declaring new variables.MigrateDBlogs a failed migration instead of ignoring it.AddTrafficusesdatabase.GetDB().Transaction(...), which surfaces the commit error, in place of the manual begin/defer/commit block.Validation
go build ./internal/...clean.go test ./internal/web/service/ ./internal/web/service/outbound/green onmainatece16559with this applied.mainwithout conflict.Risk
Low, and it is a behaviour change only in the failing case: a migration that would previously have committed half-applied now rolls back and is logged. No schema, API, or configuration change.
AddTraffic's signature and its(error, bool)contract are unchanged.