Repository navigation
refactor(store): numbered migration files instead of a hand-typed SCHEMA_VERSION - #427
Merged
Merged
Conversation
…EMA_VERSION One file per step in sentient/store/migrations (NNNN_<what>.py or .sql); SCHEMA_VERSION is the highest number. Steps 1-12 port what Store.open and the services' ensure_column calls did, columns that arrived without a bump go in the step after the version they arrived at (task_runs.sources in 8), and the skill check columns (#386) get step 13. The schema.sql files now hold the whole current shape; a new database runs no steps. ADR 0030. Closes #424
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Closes #424
What changed
One file per migration step in
sentient/store/migrations/(NNNN_<what>.pywithasync def migrate(store), orNNNN_<what>.sqlfor statements that are safe to run twice).SCHEMA_VERSIONinsentient/store/db.pyis nowMIGRATIONS[-1].number, found from the files, never typed by hand.Store.open: an existing database below the latest version gets the snapshot (Backup, restore and snapshots before migrations #151, unchanged), then runs the steps above its version in order and stampsPRAGMA user_versionafter each one. After that theschema.sqlfiles run and add any missing tables and indexes. A new database runs no steps: theschema.sqlfiles now hold the whole current shape.Steps 1-12 port the old behaviour. I traced every
ensure_columnback through git history to the commit that added it and theSCHEMA_VERSIONat that point:sessions.incognito, 3messages.sources, 4tasks.notepad, 5sessions.model, 6approval_grants, 7usage.cost_usd, 8evolution_reviews.activity_mark, 9messages.approval, 10 try runs and file snapshots, 11 memory scopes pluschecks, 12folders.scope).channel_chats.is_grouparrived at 11, so it is in 12.Step 13 (new):
skill_stats.check_reportandpending_check_report(Outcome checks, part 2: skill validation before proposing, and read-back for Home Assistant #386) arrived at version 12 without a bump, so they get their own step. The version goes from 12 to 13.Packages no longer call
store.ensure_columnon start (tasks, memory, skills, channels, integrations, evolution, reminders, snapshots). The columns that only those calls used to add are now in theirschema.sql:tasks.keep_running,task_runs.last_activity_atandidx_tasks_next_execchannel_chats.is_groupandowner_idfacts.recall_count,last_recalled_atandmerged_*integrations.statusanderrorskill_statscolumnsidx_facts_scopeandidx_usage_paidtests/test_migrations.pyfails when:.pystep has nomigrate;tests/schemas/were dumped by starting the 716658a and 4a5cb2d builds' apps.It also checks that a step that fails part way leaves the version at the last finished step, and that a new database runs no steps. On its first run it caught a real slip: I had put
task_runs.sourcesin step 1, but it arrived at version 7, so it belongs in step 8.Docs:
sentient/AGENTS.mdand the snapshot notes in docs/API.md are updated.Packaging: the frozen engine already collects every
sentient.*submodule, and PyInstaller's pkgutil hook lists modules from the PYZ archive, so the.pysteps are found (verified below). The spec now also shipsmigrations/*.sqlas data.Changelog:
changes/424.changed.md(the towncrier layout from ci: changelog entries as one file per change in changes/ (towncrier) #418).Real test
No model calls. Every home's model addresses pointed at a closed port, and the engines ran on port 8786 with a random token and their own
SENTIENT_HOMEon D:.SCHEMA_VERSION = 8) in a separate worktree and ran its owndesktop/scripts/seed-*.pyin the documented order (Maya Rao persona). That gaveuser_version 8with 13 chats, 86 messages, 20 tasks, 12 task runs, 60 memories, 5 summaries, 9 skill stats rows and 22 notifications.python -m sentient serve --port 8786):snapshot sentient-snapshot-20261017-150042.zip taken before updating the database (version 8 to 13). The zip holdssentient.dbatuser_version 8with 13 chats.sentient.dbis atuser_version 13and hasskill_stats.check_report,task_runs.sourcesandfolders.scope.GET /api/sessions: 13 chats ("Bills and a dinner booking"...).GET /api/sessions/demo-chat-readme/messages: 10 messages.GET /api/tasks: 20 tasks ("Evening Brief", "Daily Brief"...).GET /api/memories: 60 memories ("Maya prefers dark mode in every app"..., scopepersonal).GET /api/memories/summaries: 5.GET /api/skills: 7 active and 3 pending.GET /api/notifications: 22.GET /api/backups: the snapshot, reason "before updating the database (version 8 to 13)",schema_version 8.user_versionis 13.facts_vec,summaries_vec,user_insights_vecand their shadow tables), which are made at run time once the seeded home has embeddings.origin/main(b213dbe) and compared it with the new engine's result: 77 tables, 30 indexes and 5 triggers each, 0 differences (columns compared without order). The only difference is version 12 against 13.packaging/sentient-engine.spec(PyInstaller 6.22) and startedsentient-engine.exe serveon another copy of the version-8 home. It loggedsnapshot ... taken before updating the database (version 8 to 13)and served 13 chats, 20 tasks and 60 memories over REST, so the steps are found inside the frozen build too.pytest -q: 2477 passed, 2 skipped (13 min).ruff check sentient tests packagingis clean.For the owner
0014_..., git won't show a conflict because the file names differ. The test fails onmain(or on the second PR after a rebase) with "two migrations share a number", and that PR renames its file. This is documented in DEVELOPING.md.Summary by CodeRabbit