Skip to content

Commit 93b26b7

Browse files
committed
fix(import): use Value.absent() for missing companion fields
Drift's Value(null) sets the column to NULL - it does NOT mean 'leave this field untouched'. Re-importing a MacDive UDDF whose new data was missing fields the existing row already had would silently wipe those fields. All nullable-field writes to DivesCompanion and DiveSitesCompanion now use Value.absent() when the source value is null, preserving existing data on partial re-imports. Addresses Copilot review comments 1 and 2 on PR #252.
1 parent 2a5d23d commit 93b26b7

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

lib/features/dive_import/data/services/uddf_entity_importer.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,12 @@ class UddfEntityImporter {
822822
await repository.applyImportedMetadata(
823823
createdSite.id,
824824
DiveSitesCompanion(
825-
waterType: Value(waterType),
826-
bodyOfWater: Value(bodyOfWater),
825+
waterType: waterType != null
826+
? Value(waterType)
827+
: const Value.absent(),
828+
bodyOfWater: bodyOfWater != null
829+
? Value(bodyOfWater)
830+
: const Value.absent(),
827831
),
828832
);
829833
}
@@ -1222,12 +1226,22 @@ class UddfEntityImporter {
12221226
await repos.diveRepository.applyImportedMetadata(
12231227
diveId,
12241228
DivesCompanion(
1225-
diveNumberOfDay: Value(diveNumberOfDay),
1226-
boatName: Value(boatName),
1227-
boatCaptain: Value(boatCaptain),
1228-
diveOperator: Value(diveOperator),
1229-
surfaceConditions: Value(surfaceConditions),
1230-
weatherDescription: Value(weather),
1229+
diveNumberOfDay: diveNumberOfDay != null
1230+
? Value(diveNumberOfDay)
1231+
: const Value.absent(),
1232+
boatName: boatName != null ? Value(boatName) : const Value.absent(),
1233+
boatCaptain: boatCaptain != null
1234+
? Value(boatCaptain)
1235+
: const Value.absent(),
1236+
diveOperator: diveOperator != null
1237+
? Value(diveOperator)
1238+
: const Value.absent(),
1239+
surfaceConditions: surfaceConditions != null
1240+
? Value(surfaceConditions)
1241+
: const Value.absent(),
1242+
weatherDescription: weather != null
1243+
? Value(weather)
1244+
: const Value.absent(),
12311245
),
12321246
);
12331247
}

0 commit comments

Comments
 (0)