Refuse writes when the database schema is ahead of the binary #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "schema-compatibility-guard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Several peachmem servers share one Postgres database and migrate it at startup. A newer binary can migrate a database that older servers still hold open, and those servers would keep writing against the new schema.
This PR enforces one invariant: if the database schema is ahead of the binary, reads proceed and every write is refused, with a message telling the user to restart Claude Code.
schema::guarded_txis the single write choke point. Inside each write's own transaction it takes sqlx's migration lock in shared mode and then checks the applied version, so a write either sees a committed migration or waits for it.save_note,delete_note, andlink_projecteach run in one transaction. Before this, a failure partway throughsave_notecould leave a note inserted with unsynced links, projects, and paths.HANDOFF.mdis removed. It was the resume guide for this branch and said to delete it on merge.kerryhatcherregistry from commit63014de.Points for review
cargo install peachmem --registry kerryhatcher) now resolves to 0.4.0. It clears a refusal only while the database schema is at or below the binary's version. Once a migration 0005 exists, that fallback will need a newer release.docs/pi-extension-plan.mdis excluded from the crate package.Verification
cargo test --features db-testsagainst the dev database on port 55433: 59 unit, 45 knowledge, 29 schema_guard, all passing.cargo test(no database): passing.cargo clippy --all-targets --features db-tests: no warnings.save_noteis refused naming both schema versions, andlist_notessucceeds.cargo fmt --checkstill fails, but only on code that predates this branch (config,knowledge,links,topic,tests/knowledge,worklog, and a few older hunks inprojectsandstore).Deviations from the plan
Recorded in the execution ledger during implementation. The main ones:
link_projectruns its whole resolution inside the guarded transaction, so a refused call creates nothing; the partial-write test injects its failure with a trigger, because no natural failure happens after the note row is written; and a few expected test counts in the plan were stale.🤖 Generated with Claude Code