From 904ee5ec2c60cbe7d46c28d37e2ce155dcf7e181 Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Tue, 21 Oct 2025 16:56:09 -0700 Subject: [PATCH] feat: sync location root entry before syncing location --- core/src/location/manager.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/location/manager.rs b/core/src/location/manager.rs index d5b79cee0..99177fcbb 100644 --- a/core/src/location/manager.rs +++ b/core/src/location/manager.rs @@ -165,8 +165,19 @@ impl LocationManager { txn.commit().await?; info!("Created location record with ID: {}", location_record.id); - // Sync location to other devices (has FK relationships: device_id, entry_id) + // Sync location root entry FIRST (before location) to ensure FK dependency exists + // Location references entry_id, so entry must exist in sync system before location is synced use crate::infra::sync::ChangeType; + library + .sync_model_with_db(&entry_record, ChangeType::Insert, library.db().conn()) + .await + .map_err(|e| { + warn!("Failed to sync location root entry: {}", e); + e + }) + .ok(); + + // Now sync location to other devices (has FK relationships: device_id, entry_id) library .sync_model_with_db(&location_record, ChangeType::Insert, library.db().conn()) .await