Persistence
Read First
src/lib/db.tsfor the current Dexie version and upgrade history.src/store/store.tsfor debounced position/full saves and state initialization.src/lib/backup.tsfor.thotexport/import behavior.src/lib/types.tsfor persisted shapes.
Change Rules
- Treat
src/lib/db.tsas an append-only schema history. Add a newversion()for persisted schema/index changes; do not rewrite old migrations. - Add upgrade logic for old records when a new required field cannot be safely defaulted at read time.
- Preserve existing debounce and transaction behavior. Account for the fact that an immediate IndexedDB read after a mutation can observe the previous value.
- Check all lifecycle paths for changed fields: create, import, duplicate, trash, restore, permanent delete, checkpoint, backup export, and backup import.
- Keep
diagramsanddiagramsMapsynchronized in Zustand. Avoid direct partial state updates that leave the map stale. - If a change affects backups, update validation and date rehydration deliberately. Backups currently cover diagrams, selected diagram state, and AI chat sessions, not every local table.
- Use Dexie transactions for multi-table replacement or clear-and-restore operations.
Verification
- Test a fresh database and representative existing records when adding a migration.
- Verify reload persistence after normal edits, position-only edits, imports, restores, and deletion.
- Check backup round trips and confirm invalid backup input does not partially replace local data.
- Run
pnpm run type-check,pnpm run lint, andpnpm run build.