Data loss: No backup before import — importAllData destroys data with no rollback #8

Closed
opened 2026-05-16 03:41:59 +00:00 by Mark · 1 comment
Owner

Severity: HIGH (data loss)

Location

src/lib/db.ts:273-298 — importAllData() function

Description

Before importing, importAllData() immediately clears ALL IndexedDB tables, then bulk-adds the new data. There is no snapshot, no backup, no rollback:

await db.people.clear();
await db.interactions.clear();
await db.gifts.clear();
await db.dateEvents.clear();
await db.groups.clear();
await db.settings.clear();

await db.people.bulkAdd(data.people);      // if this fails, data is gone
await db.interactions.bulkAdd(data.interactions);
// ...

Impact

  • Irreversible data loss: Once .clear() runs, old data is gone even if the import fails mid-way
  • Partial corruption: If bulkAdd() fails partway through (disk full, corrupted JSON), some tables are empty while others have partial data
  • No undo: No mechanism to revert to the previous state
  • Amplified by #6 (no schema validation): invalid import payloads are statistically guaranteed to fail at some point

Recommendation

Before clearing, serialize the full DB state as a backup. On failure or cancellation, restore from the snapshot. Dexie supports this pattern natively via transaction rollback — but only if the validation happens before the clear.

Code context

  • src/lib/db.ts:273-298 — entire importAllData function
  • Related to: #6 (no schema validation on import)
## Severity: HIGH (data loss) ### Location `src/lib/db.ts:273-298` — `importAllData()` function ### Description Before importing, `importAllData()` immediately clears ALL IndexedDB tables, then bulk-adds the new data. There is no snapshot, no backup, no rollback: ```typescript await db.people.clear(); await db.interactions.clear(); await db.gifts.clear(); await db.dateEvents.clear(); await db.groups.clear(); await db.settings.clear(); await db.people.bulkAdd(data.people); // if this fails, data is gone await db.interactions.bulkAdd(data.interactions); // ... ``` ### Impact - **Irreversible data loss**: Once `.clear()` runs, old data is gone even if the import fails mid-way - **Partial corruption**: If `bulkAdd()` fails partway through (disk full, corrupted JSON), some tables are empty while others have partial data - **No undo**: No mechanism to revert to the previous state - Amplified by #6 (no schema validation): invalid import payloads are statistically guaranteed to fail at some point ### Recommendation Before clearing, serialize the full DB state as a backup. On failure or cancellation, restore from the snapshot. Dexie supports this pattern natively via transaction rollback — but only if the validation happens before the clear. ### Code context - `src/lib/db.ts:273-298` — entire importAllData function - Related to: #6 (no schema validation on import)
Author
Owner

Fixed in commit. Closing.

Fixed in commit. Closing.
Mark closed this issue 2026-05-16 05:17:04 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/kimi_agent_kin_app_sync#8
No description provided.