Repository navigation
fix(store): back up sqlite stores only before a pending migration - #33
Merged
Merged
Conversation
Every store open (schema list, embed search, ...) left a new .dbs/*.bak: openSchemaStore/openEmbedStore called kit sqlstore.BackupBeforeMigrate unconditionally; that helper is a plain copy primitive, and the stores recorded no schema revision to gate on. - schema + embed stores: SchemaVersion stamped into PRAGMA user_version inside the migrate tx; raised, never lowered - internal/dbbackup: BeforeMigrate copies only when recorded revision < target (read-only probe); unreadable file -> copy anyway - retention: newest 5 backups per store, ordered by name timestamp; other stores' copies + unrelated files untouched - stamp-less stores from earlier builds: one copy on first open, existing clutter trimmed to 5; later opens copy nothing - openers: only the backup block changed - docs: state table + backup/rollback note, XDG_STATE_HOME row, troubleshooting row for .bak clutter
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.
foo backs up its SQLite stores only when a migration is pending, and keeps the newest 5 backups.
Bug
schema.goandembed.gocalledsqlstore.BackupBeforeMigrateon every store open, so everyschema list/embed searchadded a.dbs/*.bakfile. kit'sBackupBeforeMigrateis a plain copy by design (deciding whether to back up is the caller's job), and foo's stores recorded no schema revision to decide with. No kit change needed.Fix
internal/schemaandinternal/embedstores getSchemaVersion = 1;migrate()runs setup in a transaction and stampsPRAGMA user_version(only raises it, so a file from a newer foo keeps its revision).internal/dbbackup.BeforeMigrate(dbPath, target): reads the stamp read-only and copies (via kit'sBackupBeforeMigrate) only when it's below target; an unreadable file is copied anyway.dbbackup.Keep) in$XDG_STATE_HOME/foo/.dbs/, pruned right after a new backup, ordered by the timestamp in the name; files not named like that store's backups are never touched.Tests
internal/dbbackup(no backup on repeated opens / newer stamp; exactly one on a pending migration; unreadable file; retention with unrelated files kept; timestamp ordering), store version stamp tests,cmd/foo/commands/storeopen_test.go(repeated opens leave 0 backups; an older store gets exactly 1 over 3 opens). Rebased on #32; its dry-run no-write tests pass.Docs
concepts.md(state table, backup/retention/rollback),config.md(XDG_STATE_HOME),troubleshooting.md(.bakclutter).