The import process safely restores timeline data while preserving all relationships between items. Two key challenges are handled:
- Maintaining database constraints during import
- Preserving edge relationships between items
During this phase, all records are imported with null edge relationships to avoid foreign key constraint issues:
-
Places imported first
- No dependencies on other records
- Preserves all place metadata and visit stats
- Handles duplicate places via upsert
-
Timeline Items imported next
- Visit/Trip type preserved
- Place relationships maintained
- Edge relationships temporarily nulled
- Edge information stored in JSONL format
- All other metadata preserved
-
Samples imported last
- Maintains chronological order
- Preserves timeline item relationships
- All derived/computed data included
The import process uses a two-phase approach for handling edge relationships to maintain database constraints:
-
During item import:
- Items are imported with null edge relationships
- Original edge relationships preserved in temporary JSONL file
- Each record captures itemId, previousId, and nextId
- Ensures valid database state during import
-
After items imported:
UPDATE TimelineItemBase
SET previousItemId = ?, nextItemId = ?
WHERE id = ?
- Edge relationships restored from JSONL records
- Processed in batches of 100 records
- Single transaction per batch for safety
- Foreign key constraints enforced
- No dependency on edge healing system
- Temp file removed after successful restore
- Cleanup of edge record file on failure
- Clear state management through PersistenceActor
- Safe resumption from last successful batch
- Safe to import from directories that may be updated
- Uses metadata timestamps to understand data window
- Handles incremental backup directories correctly
- Schema version compatibility check
- Required fields validation
- Foreign key integrity verification
- Date range continuity validation
- Transaction rollback on failures
- Detailed error reporting
- Partial import recovery where possible
- Verification of restored state
- Batched record imports (100 records per batch)
- Memory usage management through batching
- Efficient JSONL format for edge records
- Background import option for large datasets