Keep a profile save away from the timezone column

This commit is contained in:
Roland Geider
2026-08-24 15:56:23 +02:00
parent 1b80ad5ee1
commit cb7faba67b
2 changed files with 15 additions and 1 deletions

View File

@@ -44,12 +44,14 @@ class UserProfile {
int get defaultWeightUnitId => isMetric ? WEIGHT_UNIT_KG : WEIGHT_UNIT_LB;
/// Drift companion for local UPDATE writes routed through PowerSync.
///
/// Only the columns the profile form edits: the timezone column belongs to
/// TimezoneSync, and a full write would clear what another client reported.
UserProfileTableCompanion toCompanion() {
return UserProfileTableCompanion(
id: drift.Value(id),
weightUnitStr: drift.Value(weightUnitStr),
height: drift.Value(height),
timeZone: drift.Value(timeZone),
);
}
}

View File

@@ -114,6 +114,18 @@ void main() {
expect(row.height, 178);
});
test('leaves the reported timezone alone', () async {
// The column belongs to TimezoneSync; the server rejects it as null,
// taking the rest of the profile write down with it
await seed();
await repo.updateTimeZoneDrift(1, 'Pacific/Auckland');
await repo.editLocalDrift(UserProfile(id: 1, weightUnitStr: 'lb'));
final row = await db.select(db.userProfileTable).getSingle();
expect(row.timeZone, 'Pacific/Auckland');
});
test('clears the height when the profile has none', () async {
// The server allows a profile without one, so an emptied field has to
// reach the column as NULL rather than leaving the old value standing