feat(core): version the store schema with a migration runner#50
Merged
Conversation
The store applied its schema with CREATE TABLE IF NOT EXISTS on every open, so a change to an existing table would silently never reach databases already sitting on a volume. The store now keeps an ordered, append-only migration list and records the schema version in the SQLite file via PRAGMA user_version: each pending migration runs in its own transaction, a failure rolls back cleanly and retries on next open, and a database written by a newer build is refused instead of opened. Migration 001 is the existing schema, kept idempotent so databases created before versioning replay it harmlessly on first open. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3167c7d to
05565f3
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.
What
The store applied its schema with
CREATE TABLE IF NOT EXISTSon every open. That works until the first release that changes an existing table: databases already sitting on a volume keep the old shape and the agent starts failing at insert time. This PR gives the store a schema version and a migration runner.How
packages/core/store/migrations.tsholds an ordered, append-only list of migrations. The array position is the schema version, recorded in the database itself viaPRAGMA user_version, so there is no extra journal table.Storeapplies each pending migration inside its own transaction and bumps the version in the same transaction. A failed migration rolls back completely and the next open retries from the same point.memoriestable from Persistent agent memory #37, kept idempotent (IF NOT EXISTS) on purpose: databases created before versioning report version 0 with some or all tables already present, and replay it harmlessly on first open.No new dependencies; the runner is ~40 lines on
node:sqlite.Testing
deno task okpasses (fmt, lint, check, 112 tests).Store, confirmed existing rows survive and the file gets stamped to version 1.🤖 Generated with Claude Code