feat: add storeNames to ImportOptions for selective restore - #73
feat: add storeNames to ImportOptions for selective restore#73Atharva0506 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. Walkthrough
ChangesSelective restore
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR adds optional selective store restoration while preserving existing behavior when omitted; no actionable merge-blocking risk remains beyond normal checks and review. Suggested labels: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The implementation satisfies issue ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
`ExportOptions` already supports `storeNames`, so a backup could be produced selectively but not consumed selectively. Callers wanting a partial restore had to filter `backupData.stores` themselves, coupling them to the envelope shape. `importDB` now accepts an optional `storeNames` list. When present, only the named stores are repopulated; when omitted, behaviour is unchanged. The filter applies to records only — schema creation is untouched, so stores left out of the list still exist after the import (empty under "overwrite", unchanged under "merge"). That keeps a partial restore from breaking app code that opens a store it did not restore, and matches the semantics of the `backupData.stores` workaround it replaces.
e0c5842 to
89c4f46
Compare
Addressed Issues:
Fixes #67
Screenshots/Recordings:
N/A — library-only change, no UI. Behaviour is covered by the new tests.
Before (caller has to reach into the envelope):
After:
Additional Notes:
What changed
ImportOptionsgainsstoreNames?: string[], mirroringExportOptions.storeNames.importDBnarrows its target-store list by that selection. Omitting it keeps the previousbehaviour exactly, so this is backwards compatible.
exportDBtreats them(
src/core/exporter.ts).storeNames: []restores no records.Design decision worth a reviewer's eye:
storeNamesfilters records, not schema.openDatabaseForImport/createStoresFromSchemaare deliberately untouched, so the full backupschema is still created and a store left out of
storeNamesexists but is not populated (emptyunder
overwrite, unchanged undermerge).The alternative — filtering
schematoo — would mean anoverwritepartial restore leaves theunlisted stores absent entirely, so any app code touching one hits
NotFoundErroruntil itupgrades the DB itself. It also would not match the
backupData.storesworkaround this replaces,which never touched
schema. For the issue's motivating case that distinction is the whole point:the 6 RPC cache stores need to exist so they can be refetched.
Tests — 7 new cases in
tests/importer.test.ts: overwrite restores only listed stores (unlistedexist but empty); merge leaves unlisted stores' existing records untouched; omitted
storeNamesrestores everything;
[]restores nothing but still creates the schema; unknown names ignored;all-unknown resolves without throwing; duplicate entries do not double-insert (
overwriteusesadd(), so a second pass would surface asConstraintError). 5 of the 7 fail without the change;the other 2 are regression guards for the default path.
Verification —
npm test63 passed (6 files),npm run lintclean,npm run buildclean(ESM + CJS + d.ts,
storeNamespresent in the emitted declarations).npm run format:checkreports 12 files, but that is pre-existing onmain— it fails identicallywith this branch stashed, and it flags files this PR does not touch
(
src/core/exporter.ts,src/core/migrations.ts,src/utils/ssr.ts, …). Running Prettier againstthe three changed files with the project config shows zero deviations in
src/types/index.tsand
tests/importer.test.ts, and insrc/core/importer.tsevery deviation sits above line 254 —all of it pre-existing code, none in the new region. Reformatting the repo here would bury the
feature diff, so I left it out; happy to fix it in a separate
style:PR if you want.Version —
VERSIONis intentionally untouched, since a push to it onmaintriggers tag +release + npm publish via
version-release.yml. This is an additive optional field, so it is aminor bump:
1.0.1→1.1.0whenever you want to cut the release (possibly batching #68).Checklist
AI Assistance Disclosure
Written with Claude Code, model
claude-opus-5[1m](Claude Opus 5, 1M context).The design decision above (records-vs-schema filtering) was reviewed and chosen by me, and the
build, lint, and test results were verified locally before opening this PR.
Summary by CodeRabbit
New Features
Documentation