fix: seed import update mode fills gaps only — MSFS is primary

Changes  behavior: ALL fields now use ONLY_IF_EMPTY
policy for existing assets. Previously, AUTO fields (name, make, model,
company, place, building_name, floor, etc.) always overwrote existing
data, clobbering MSFS-synced and manually-cleaned records.

- db_writer.py: update() treats every field as 'skip if existing
  value non-null' — same as old PRESERVE behavior but universal
- sync.py: UPDATE path now fetches current values and only sets
  fields that are currently NULL/empty
- New assets (not found by machine_id) still insert with full seed data
- sync.py docstring and stats output updated to reflect new policy

Closes #13 — seed import no longer overwrites MSFS data
This commit is contained in:
2026-06-02 22:50:53 -04:00
parent 9888601863
commit 186a9d03f3
2 changed files with 31 additions and 25 deletions
+15 -5
View File
@@ -138,7 +138,7 @@ def push(source_db: str, target_db: str, dry_run: bool = False) -> dict:
location_id = 0
existing = tgt.execute(
"SELECT id FROM assets WHERE machine_id = ?", (mid,)
"SELECT * FROM assets WHERE machine_id = ?", (mid,)
).fetchone()
# Category mapping
@@ -214,12 +214,22 @@ def push(source_db: str, target_db: str, dry_run: bool = False) -> dict:
}
if existing:
# MSFS is primary — seed fills gaps only
# Build filtered update dict: only set fields that are currently empty
existing_dict = dict(existing)
filtered_data = {}
for col, val in asset_data.items():
current = existing_dict.get(col)
if current is None or str(current).strip() == "":
filtered_data[col] = val
report["assets_updated"] += 1
if len(report["first_10"]) < 10:
report["first_10"].append(f"UPDATE {mid}: {name} ({cat})")
if not dry_run:
sets = ", ".join(f"{col} = ?" for col in asset_data)
vals = list(asset_data.values()) + [mid]
skipped_fields = len(asset_data) - len(filtered_data)
report["first_10"].append(f"UPDATE {mid}: {name} ({cat}) — {len(filtered_data)} fields, {skipped_fields} skipped (MSFS/cleanup data preserved)")
if not dry_run and filtered_data:
sets = ", ".join(f"{col} = ?" for col in filtered_data)
vals = list(filtered_data.values()) + [mid]
tgt.execute(
f"UPDATE assets SET {sets} WHERE machine_id = ?",
vals,