fix(upgrade): stop re-sealing step registry on every boot - #204
Open
rguedes wants to merge 1 commit into
Open
Conversation
Dev builds never call writeVersion, so no app.version row is ever created. Each boot then reads the missing row as a fresh install and re-inserts the whole step registry, failing with a duplicate key violation on upgrade_steps and aborting startup. Persist the version in the fresh-install branch as well, and make the seal idempotent with ON CONFLICT DO NOTHING so databases already left in the broken state (steps present, no app.version) can boot again. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
On every startup the server aborts with:
Root cause
runLockedonly persistsapp.versionwhen!IsDev(binaryVersion). A dev build therefore never writes the row, soreadVersionkeeps returningfresh = trueon every boot,markAllAppliedre-inserts the whole registry, and the insert collides with the rows written by the first successful boot.Secondary effect: because a dev build is always "fresh", newly added registry steps get auto-sealed instead of applied, so they can never be exercised locally.
Fix
IsDev. The next boot takes theIsDevbranch (version pin still skipped) andapplyPendingruns any new steps normally.ON CONFLICT DO NOTHING, so databases already stuck in the broken state (steps present, noapp.version) can boot again without manual SQL.Testing
go build ./...andgo vet ./internal/storage/migration/upgrade/pass. No unit test added — the package has no database test harness (Postgres-only, no sqlite driver in the module).🤖 Generated with Claude Code