feat(db): pre-migration backup + version gate + restore#14
Merged
Conversation
Context: Add a safety net around IndexedDB schema upgrades. Changes: Introduce prepareConnection/version gate checks; create tiered pre-migration backups; add restore/emergency restore flows; add regression tests. Impact: Prevents silent data loss during upgrades and blocks opening a newer DB with an older app. Tests: npx tsc --noEmit; npm test -- --run Docs: Updated docs/WORKLOG.md
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary\nAdd a migration safety net for IndexedDB upgrades: version gate + automatic pre-migration backups + restore path.\n\n## Root Cause\nSchema upgrades previously ran without a safety backup and without a guardrail for "DB newer than app" scenarios.\n\n## Changes\n- [ ] services/db/core/versionGate.ts: peek DB version (no upgrade) and return actionable status\n- [ ] services/db/core/migrationBackup.ts: export-and-store backup before upgrades (tiered storage)\n- [ ] services/db/core/migrationRestore.ts: restore from backup / emergency restore helper\n- [ ] services/db/core/connection.ts: add prepareConnection() + integrate safety flow; avoid open() stampede\n- [ ] services/db/core/errors.ts: treat DbError kind 'Version' as requiresUserAction\n- [ ] tests/db/migrations/*: add coverage for version gate, backup, restore\n\n## Testing\n- [x] npx tsc --noEmit\n- [x] npm test -- --run\n\n## Review Checklist\n- [x] No direct commits to main\n- [x] One issue per PR\n- [x] Tests pass locally\n\n## Follow-ups\n- services/db/core/connection.ts is ~346 LOC (above the 300 LOC guideline); consider a small decomposition PR later.