Repository navigation
V0-16: Add rotating backup, restore, and migration safety - #36
Merged
Merged
Conversation
Local rotating backup, restore, and migration safety for the durable SQLite database. Backups live in the macOS application-data folder under a `backups` subdirectory, are produced with SQLite-safe `VACUUM INTO` semantics (never a naive copy of a live WAL database), and carry a JSON manifest with schema version, created time, app version, sha256 checksum, and backup kind. - `src-tauri/src/backup.rs` owns backup creation, validation (checksum + integrity + supported schema), retention (seven automatic; four each pre-migration/pre-restore), a full-scan data fingerprint, and atomic file replacement that preserves the current database on any failure. - `WorkspaceStore::open_with_backup` guards every pending migration with a verified pre-migration backup or aborts without migrating. The migrations list is extracted so the pending count and the migrator share one source. - `WorkspaceStore::maybe_automatic_backup` runs at most once per local calendar day, only after durable data changed since the last backup. Tracking state lives in a sidecar file so recording it never changes the fingerprint it compares against. - The `restore_backup` command re-validates the selected backup, makes a pre-restore backup, closes the live connection, swaps files atomically, and reopens (migrating an older-schema backup forward behind its own pre- migration backup). An invalid backup never replaces current data. - The recovery screen lists valid local backups and restores one after explicit confirmation; it works even when storage would not open. Closes #17.
- Drop the FTS virtual table from the fingerprint (it duplicated the notes signal the comment said was being avoided) by excluding the whole note_search family. - Simplify integrity_check's open-failure mapping to |_| BackupError::Corrupt. - Document the UTC-day decision in day_of and the simplicity audit; the audit now reflects the backup-state.json sidecar, not app_preferences rows. - Import WorkspaceSnapshot at the top of storage-recovery.tsx and restore the trailing newline. - Add the two missing scenario tests: a failed pre-restore backup preserves the current database, and a tampered-source replacement preserves the current database. - Remove the unused backup_count test helper.
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.
Closes #17.
What this adds
Local rotating backup, restore, and migration safety for the durable SQLite database. Backups live in the macOS application-data folder under a
backupssubdirectory, are produced with SQLite-safeVACUUM INTOsemantics (never a naive copy of a live WAL database), and carry a JSON manifest sidecar with schema version, created time, app version, sha256 checksum, and backup kind.src-tauri/src/backup.rs— a new deep module owning backup creation, validation (checksum +PRAGMA integrity_check+ supported schema), retention (seven automatic; four each pre-migration/pre-restore), a full-scan data fingerprint, and atomic file replacement that preserves the current database on any failure. Connection-agnostic.WorkspaceStore::open_with_backup— guards every pending migration with a verified pre-migration backup, or aborts without migrating. The migrations list is extracted so the pending-count check and the migrator share one source.WorkspaceStore::maybe_automatic_backup— at most once per calendar day, only after durable data changed since the last backup. Tracking state lives in abackup-state.jsonsidecar so recording it never changes the fingerprint it compares against.restore_backupcommand — re-validates the selected backup, makes a pre-restore backup, closes the live connection, swaps files atomically, and reopens (migrating an older-schema backup forward behind its own pre-migration backup). An invalid backup never replaces current data; every failure reports a typed recovery state.Acceptance criteria coverage
automatic_backup_runs_at_most_once_per_day_and_only_after_data_changesretention_keeps_the_latest_seven_automatic_backupsa_pending_migration_is_preceded_by_a_pre_migration_backup,a_migration_aborts_without_changing_schema_when_the_pre_migration_backup_failsa_checksum_mismatch_is_rejected_before_restore,a_corrupt_sqlite_file_is_rejected,an_unsupported_schema_version_is_rejectedrestore_replaces_the_database_and_reopens_to_match_the_backupa_failed_pre_restore_backup_preserves_the_current_database,a_replacement_with_a_tampered_source_preserves_the_current_database,replace_database_restores_the_live_file_when_the_target_disappearsTesting decisions coverage
WAL-active backup, retention, unchanged day, checksum mismatch, corrupt SQLite, unsupported schema, failed pre-restore backup, failed replacement, successful reopen, and migration backup ordering + abort are each covered by a named test. A deterministic clock is supplied via the
nowparameter and a temporary app-data directory is used per test.Notes
day_ofand the simplicity audit.docs/audits/issue-17-simplicity-audit.md.fallow auditand the two-axis code review both report zero introduced findings; the only fallow complexity finding is the pre-existingAppcomponent (introduced: false), out of scope.Gates
npm run typecheck,npm run lint(max-warnings 0),cargo test --lib(177 passed), 8000 andcargo checkall pass.Do not merge without review.