feat(db): pre-migration backup + version gate + restore #14
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.