When I try to delete all cloud items, this only seems to remove the cards but not their related cloud 'items'. Should include related items table but not media. Also, for some reason, at present, Even I try to import .xlsx backup, this seems to load everything ok but then everything gets auto deleted as if some sync function is prioritizing the cloud as the authoritative source over the local. The local storage and indexedDB needs to take priority. For the export to xlsx, let's add export of command presets, quote templates themes, app theme templates and link sources. If not clear ask for clarifying questions. -- Here's a well-structured prompt you can use with Lovable.dev: --- ## Prompt for Lovable.dev **Title: Implement Tombstone Column for Safe IndexedDB-Cloud Sync** I need to implement a tombstone pattern for deleted items to safely sync between IndexedDB and cloud storage. **Problem:** - When a user deletes an item locally (IndexedDB), it needs to be deleted from the cloud - If the cloud still has the item but local is deleted, the system needs to recognize this was intentional - Currently there's no way to distinguish between "never synced" and "was deleted" **Solution: Tombstone Column** Add a `deletedAt` timestamp column to the IndexedDB schema: **Schema Changes:** - Add `deletedAt: number | null` field to all synced items - `null` = item is active - `timestamp` = item was deleted at this time, pending cloud sync **Implementation Requirements:** 1. **Local Deletion Logic:** - Instead of removing records, set `deletedAt = Date.now()` - Mark item as `isDirty = true` for sync queue - Soft delete in UI (hide/gray out items where `deletedAt !== null`) 2. **Sync to Cloud:** - When syncing, send items with `deletedAt` timestamps to cloud - Cloud should delete the item and/or store deletion timestamp - After successful cloud sync, hard delete the local record 3. **Cloud to Local Sync:** - If cloud item doesn't exist but local has it → check if `deletedAt` is set - If `deletedAt` exists → deletion was intentional, keep tombstone briefly then hard delete - If `deletedAt` is null → this is a conflict (cloud was deleted after we last synced), hard delete locally 4. **Conflict Resolution:** - Item exists locally with `deletedAt` + exists on cloud = cloud wins, remove `deletedAt` - Item exists locally with `deletedAt` + missing on cloud = local deletion wins, hard delete **What to Build:** - [ ] Add `deletedAt: number | null` to IndexedDB schema - [ ] Update deletion handlers to soft-delete - [ ] Add tombstone cleanup logic (hard delete after N days) - [ ] Update sync service to handle tombstone records - [ ] Add UI filtering to hide deleted items - [ ] Handle bidirectional sync conflicts with tombstones --- **Key Benefits of This Approach:** - ✅ Survives network failures (deletion persists locally) - ✅ Detects intentional vs accidental deletes - ✅ Works offline - ✅ Sync is idempotent (safe to retry) - ✅ Eventually consistent across devices --- This prompt clearly explains the distributed systems problem and the exact implementation pattern needed. Would you like me to elaborate on any specific part (like conflict resolution logic or the sync queue implementation)?