Repository navigation
feat: take a validated backup before an upgrade migrates the database - #106
Conversation
Re-running the installer upgrades in place, and there is no downgrade: an older executable refuses a database a newer one migrated (ADR 0023). Nothing marked the moment before the change, so the recovery point was whenever the last scheduled backup ran. serve now checks, read-only, which of its migrations an existing database lacks (storage::pending_migrations). When any are pending it takes an ordinary validated snapshot first (backup::before_migrating), logs its name with how to go back, and fails closed if the snapshot cannot be written. A new or current database takes no extra snapshot. Being an ordinary snapshot, it is retained and copied off the server like any other. Tests build a real older schema (every migration but the newest): the snapshot holds the old schema and validates, the migration then runs, nothing is pending afterwards, and an unwritable backups/ leaves the database unmigrated. Making detection report nothing pending fails two of them. The install guide and ADR 0023 describe going back. Closes #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
The ADR renumbering in #91 relabeled two links to ADR 0023 (installation lifecycle) as ADR 0024 in the install guide and the development index. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
The upgrade drill showed 0.1.0 refusing a migrated database with "migration 16 was previously applied but is missing". Startup now checks for applied migrations this build does not know before migrating, and names the way back. Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
# Conflicts: # CHANGELOG.md
Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 74e78b1d6a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
backup::run records its audit event in the database it just copied. Before migrating, that database has the old schema, which may lack the audit table (migration 0002) or the current event kinds, so startup failed after taking a good snapshot. The snapshot step now writes nothing; the pre-migration backup comes back as a must_use PreMigrationBackup whose record() writes the audit event into the migrated database. Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad460a09fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
setup-code and recover opened the database with storage::open, which migrates, so running either with a new executable before serve upgraded the installation without its recovery snapshot. backup::open_migrated is now the one way the executable opens the database for use: backup, then migrate, then audit. A guard test keeps storage::open out of main.rs. Pre-migration backups no longer prune; the CLI does not know the configured retention, and the next scheduled backup prunes with it. Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 096eb3f083
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…pshots A command other than serve now takes the serve lock when it would migrate, and refuses while a server holds it, so no running server commits records after the snapshot or runs against the new schema; pending migrations are checked again under the lock. Pre-migration snapshots are named consolebook-premigration-<stamp>.db and at most three are kept, so a migration that fails on every restart cannot fill the disk. Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
consolebook-prerestore-<stamp>.db sorted after every consolebook-<stamp>.db, so after any restore the set-aside database stayed "newest" for good: catch-up copied it off the server, copy status read current while later copies failed, and retention pruned real backups ahead of it. Closes #105 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e40a9c315d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…claude/94-pre-migration-backup
Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7356d318f2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
record_phase_event read the implicit effective instant before waiting for the write lock, then refused anything older than the newest committed event as out of order. A request that waited across a second boundary while another event committed got OutOfOrder instead of the real answer. It now reads "now" (and checks for a future instant) under the lock. Closes #108 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
…ude/94-pre-migration-backup
|
Filed as #108 and fixed in #109, with a deterministic test whose negative control reproduces exactly this failure. The fix is ported here in Generated by Claude Code |
…the backup Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3be2551e52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
serve passes its off-server copy settings to open_migrated, which copies the validated snapshot before migrating: when the migration then fails, the scheduler that would have copied it never starts. The copy is best effort; an unreachable share is logged and the next start's catch-up retries. Refs #94 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts
|
@codex review Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e96eafc5ab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Primary Issue
Closes #94
Problem And Outcome
An upgrade applies forward-only migrations, and there is no downgrade (ADR 0023). Before this PR, the recovery point for a bad upgrade was the last scheduled backup, which could be up to a day old. Now any command that would migrate the database does three things first:
An older build that meets a database upgraded by a newer one says so plainly.
Changes
backup::open_migrated(data_dir, held_lock, off_server)is the one way the executable opens the database for use.serve,setup-code, andrecoverall go through it, and a guard test keepsstorage::openout ofmain.rs. When a migration is pending, it:servepasses its own lock; other commands take it, or refuse with "stop the running service";consolebook-premigration-<stamp>.dbwithVACUUM INTOand validates it. Nothing is written to the old schema;storage.rs:pending_migrations()andnewer_migrations();open()refuses a database with migrations this build doesn't know, with a message naming the way back.docs/install.md"Upgrading": the pre-migration snapshot, which commands take it, how to find the version you upgraded from, and how to restore with that version;Correction rungs:
#[must_use]pre-migration backup whose audit can only be recorded against a migrated pool.Verification
tests/pre_migration_backup.rs, 12 tests:backups/fails closed, with nothing migrated;open_migratedbacks up, migrates, and audits once;main.rsmigrates only throughopen_migrated.no such table: audit_event);v0.1.0archive (checksum verified) and a scratch build of this branch with one drill-only migration standing in for the next release.restored the pre-migration snapshot back to schema 15.doctorpassed every check, and 0.1.0 served again under the same installation id.e96eafc(scripts/proof.py, euid 0 with DAC capabilities dropped): passed, all 7 gates. Browser suite 59 expected, 0 unexpected, 0 flaky. Receipt.proof/20261014T225745Z-e96eafc5abfb/receipt.json, sha256b24e2973b32ff910c111169e49c9463ef7e3d047c030e6e1bc225fe0e9d2e5da.🤖 Generated with Claude Code
https://claude.ai/code/session_01TsvZjbz8dTRM8A1NqAP5ts