Skip to content

fix(db): interrupted or failed migrations are no longer marked applied - #549

Merged
fclairamb merged 4 commits into
mainfrom
fix/interrupted-migrations
Oct 13, 2026
Merged

fclairamb merged 4 commits into
mainfrom
fix/interrupted-migrations

Conversation

@fclairamb

Copy link
Copy Markdown
Owner

Implements the spec from #548 (included in this branch, moved to specs/done/2026/10/).

Stopping a container during its first start left a SQLite database that never started again (no such column: organization.default_escalation_policy_uid). bun marked each migration applied before running it, so a killed or failing migration was skipped on the next boot.

  • Both backends: migrate.WithMarkAppliedOnSuccess(true). A failed or interrupted migration stays pending and runs again.
  • SQLite first boot is atomic: the DB is built as solidping.db.init, checkpointed, then renamed. Leftover .init files are deleted at start.
  • SQLite upgrades: VACUUM INTO solidping.db.pre-<migration>.bak before pending migrations, latest only, skipped when free disk is under 2x the DB size. A migration error names the backup.
  • New migrations should be .tx.up.sql (documented in wiki/conventions/migrations.md). Existing files are not renamed.
  • A startup no such column/table error is wrapped as "database looks half-migrated", with a runbook entry.

Tests: failed migration not recorded then retried (SQLite and embedded Postgres), interrupted/cancelled first boot leaves nothing, clean first boot leaves one file, backup cases.

Not done here: the manual docker check (docker rm -f 5 s into a fresh container, restart on the same volume, /api/mgmt/health is 200).

Closes #548

🤖 Generated with Claude Code

fclairamb and others added 4 commits October 13, 2026 13:39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tabases atomically

Bun recorded a migration before running it, so a container stopped during
its first start (or a migration failing half way) left a database that
claimed a schema it lacked and crash-looped on 'no such column'.

- both backends: migrate.WithMarkAppliedOnSuccess(true)
- SQLite: a missing database is built as solidping.db.init, migrated,
  checkpointed and renamed; leftovers are deleted at start
- SQLite: pending migrations on an existing database first write
  solidping.db.pre-<name>.bak (latest only, skipped under 2x free space)
- startup data fixups explain a half-migrated database

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ook, close the spec

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.37500% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.07%. Comparing base (b74bf7c) to head (9db70b7).

Files with missing lines Patch % Lines
server/internal/db/sqlite/firstboot.go 75.38% 16 Missing ⚠️
server/internal/db/sqlite/sqlite.go 94.44% 2 Missing ⚠️
server/internal/db/sqlite/diskfree_unix.go 75.00% 1 Missing ⚠️
server/internal/db/sqlite/memtemplate.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #549      +/-   ##
==========================================
- Coverage   83.08%   83.07%   -0.01%     
==========================================
  Files        1197     1200       +3     
  Lines      123358   123466     +108     
==========================================
+ Hits       102488   102573      +85     
- Misses      20862    20885      +23     
  Partials        8        8              
Files with missing lines Coverage Δ
server/internal/db/halfmigrated.go 100.00% <100.00%> (ø)
server/internal/db/postgres/postgres.go 66.48% <100.00%> (+0.05%) ⬆️
server/main.go 33.33% <100.00%> (+0.19%) ⬆️
server/internal/db/sqlite/diskfree_unix.go 75.00% <75.00%> (ø)
server/internal/db/sqlite/memtemplate.go 70.90% <66.66%> (-0.79%) ⬇️
server/internal/db/sqlite/sqlite.go 89.77% <94.44%> (+0.08%) ⬆️
server/internal/db/sqlite/firstboot.go 75.38% <75.38%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fclairamb
fclairamb merged commit c7479ed into main Oct 13, 2026
26 checks passed
@fclairamb
fclairamb deleted the fix/interrupted-migrations branch October 13, 2026 12:26
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