Skip to content

Commit 331b12f

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 d59d043 commit 331b12f

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
@@ -815,8 +815,12 @@ class UddfEntityImporter {
815815
await repository.applyImportedMetadata(
816816
createdSite.id,
817817
DiveSitesCompanion(
818-
waterType: Value(waterType),
819-
bodyOfWater: Value(bodyOfWater),
818+
waterType: waterType != null
819+
? Value(waterType)
820+
: const Value.absent(),
821+
bodyOfWater: bodyOfWater != null
822+
? Value(bodyOfWater)
823+
: const Value.absent(),
820824
),
821825
);
822826
}
@@ -1212,12 +1216,22 @@ class UddfEntityImporter {
12121216
await repos.diveRepository.applyImportedMetadata(
12131217
diveId,
12141218
DivesCompanion(
1215-
diveNumberOfDay: Value(diveNumberOfDay),
1216-
boatName: Value(boatName),
1217-
boatCaptain: Value(boatCaptain),
1218-
diveOperator: Value(diveOperator),
1219-
surfaceConditions: Value(surfaceConditions),
1220-
weatherDescription: Value(weather),
1219+
diveNumberOfDay: diveNumberOfDay != null
1220+
? Value(diveNumberOfDay)
1221+
: const Value.absent(),
1222+
boatName: boatName != null ? Value(boatName) : const Value.absent(),
1223+
boatCaptain: boatCaptain != null
1224+
? Value(boatCaptain)
1225+
: const Value.absent(),
1226+
diveOperator: diveOperator != null
1227+
? Value(diveOperator)
1228+
: const Value.absent(),
1229+
surfaceConditions: surfaceConditions != null
1230+
? Value(surfaceConditions)
1231+
: const Value.absent(),
1232+
weatherDescription: weather != null
1233+
? Value(weather)
1234+
: const Value.absent(),
12211235
),
12221236
);
12231237
}

0 commit comments

Comments
 (0)