Backup/Import system needs maintenance for PocketBase sync #9

Open
opened 2026-04-18 12:14:28 +02:00 by ben · 0 comments
Owner

Summary

The export/import system doesn't account for recent PocketBase changes and sync behavior. Several gaps exist between what's backed up and what's needed to restore a full working state.

Issues Found

1. remoteId not cleared on import (critical sync bug)

  • Imported backups keep remoteId fields from original device
  • SyncService.push() attempts to update PocketBase records with those IDs
  • If importing on different account → 404 errors or updating wrong user's data
  • Fix: Clear remoteId and remoteImageFilename on import, set isDirty=true to push to current account

2. User settings not backed up (data loss)

  • Shopping list (user_shopping_list)
  • Removed ingredients (removed_ingredients)
  • Partner data (partner_favorites, partner_email)
  • These live in SharedPreferences and are silently lost on import
  • Consider adding a userSettings.json to the ZIP alongside dishes

3. Dish created-at timestamps orphaned on import

  • PreferencesService stores dish_ca_<isar_id> keys
  • Isar IDs change on import (new autoincrement) → old keys become orphans
  • Created dates are permanently lost
  • Could be migrated into a metadata field on Dish or included separately in backup

4. isFavorite flag loses meaning when logged in

  • isFavorite exported from Isar but managed via UserSettingsService
  • On import, flags restored; on next pull() they're overwritten by remote list
  • Acceptable for offline users but confusing if synced later
  • Should document this or unify the system

Affected Code

  • lib/data/services/backup_service.dart (lines 255-266)
  • lib/data/services/preferences_service.dart (dash_ca_* keys)
  • lib/data/services/user_settings_service.dart (user settings keys)

Recommendation

Start with Issue 1 (critical) to prevent sync corruption. Issues 2–3 are data loss but less common (affect offline/restore workflows).

## Summary The export/import system doesn't account for recent PocketBase changes and sync behavior. Several gaps exist between what's backed up and what's needed to restore a full working state. ## Issues Found ### 1. remoteId not cleared on import (critical sync bug) - Imported backups keep `remoteId` fields from original device - `SyncService.push()` attempts to update PocketBase records with those IDs - If importing on different account → 404 errors or updating wrong user's data - Fix: Clear `remoteId` and `remoteImageFilename` on import, set `isDirty=true` to push to current account ### 2. User settings not backed up (data loss) - Shopping list (`user_shopping_list`) - Removed ingredients (`removed_ingredients`) - Partner data (`partner_favorites`, `partner_email`) - These live in SharedPreferences and are silently lost on import - Consider adding a `userSettings.json` to the ZIP alongside dishes ### 3. Dish created-at timestamps orphaned on import - `PreferencesService` stores `dish_ca_<isar_id>` keys - Isar IDs change on import (new autoincrement) → old keys become orphans - Created dates are permanently lost - Could be migrated into a `metadata` field on Dish or included separately in backup ### 4. isFavorite flag loses meaning when logged in - `isFavorite` exported from Isar but managed via `UserSettingsService` - On import, flags restored; on next pull() they're overwritten by remote list - Acceptable for offline users but confusing if synced later - Should document this or unify the system ## Affected Code - `lib/data/services/backup_service.dart` (lines 255-266) - `lib/data/services/preferences_service.dart` (dash_ca_* keys) - `lib/data/services/user_settings_service.dart` (user settings keys) ## Recommendation Start with **Issue 1** (critical) to prevent sync corruption. Issues 2–3 are data loss but less common (affect offline/restore workflows).
ben added this to the LovePlate project 2026-04-18 12:16:13 +02: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
ben/LovePlate#9
No description provided.