agentstategraph-migrate
Schema migration registry for AgentStateGraph databases.
What
When the substrate (agentstategraph) or a sibling crate
(agentstategraph-tasks, future crates) changes how it lays out state,
existing .db files need a forward-path. This crate provides:
- A
/_meta/schema_versionsentinel in-tree (stamped byRepository::init()). - A
Migrationtrait +Registryfor named, idempotent, commit-producing transformations taggedIntentCategory::Migrate. - A
check()entry point for consumers to detect mismatched schema versions at startup. - Stable exit codes (
exit::DOWNGRADE_REFUSED = 64, etc.) for ops. - Builtin migrations — starting with
plan_assignments_sidecar_to_nativefor a legacy pre-0.4 sidecar.
See spec/UPGRADE-PATH.md in the repo root for the design.
Consumer integration
Typical startup check, before the app opens any listener:
use Repository;
use ;
For non-interactive deployments (systemd, Docker), set ASG_MIGRATE=auto
explicitly so the behaviour is deterministic across versions.
Operator CLI
Manual / one-shot runs use the subcommand on agentstategraph-mcp:
agentstategraph-mcp migrate --db ./state.db [--to 0.5.0] [--dry-run] [--yes] [--ref main]
The subcommand does not start the server. It runs migrations, prints a report (per-migration status + commit IDs), and exits with codes above.
Rollback
No down() migrations. To roll back:
asg log --intent Migrateto find the migration commit.- Create a branch at its parent:
asg branch pre-0.5 <parent-commit>. - Point the old binary at that branch.
Data on main is preserved; the downgrade is a new ref, not a rewrite.
Registering consumer migrations
Consumers and other sibling crates can register their own migrations:
let mut registry = builtin;
registry.register;
They appear in plan() output ordered by to_version(). Each migration
is expected to:
- Be idempotent (
applies_toreturnsfalseonce done). - Produce at most one commit tagged
IntentCategory::Migrate. - Bump
/_meta/schema_versionto its declaredto_version()in that same commit. Usespec_set_json+commit_speculationfor atomicity.
License
Licensed under either of Apache License, Version 2.0 or MIT license, at your option.