From cc483f3daea44409620a4967487f2bf13ee402fa Mon Sep 17 00:00:00 2001 From: Mustafa Senoglu Date: Thu, 9 Jul 2026 14:15:04 +0300 Subject: [PATCH] fix: make routineId nullable in WorkoutLogTable to prevent crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server allows workout logs without a routine (free/ad-hoc logging), but the app's Drift table declared routineId as non-nullable. This caused a null check operator crash when PowerSync delivered a row with routine_id = NULL. Changes: - WorkoutLogTable.routineId: integer() → integer().nullable() - Log.routineId: late int → int? - Log constructor: required this.routineId → this.routineId - Log.toCompanion: handle null routineId with Value.absent() Fixes #1250 --- lib/database/powersync/tables/routines.dart | 2 +- lib/features/routines/models/log.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/database/powersync/tables/routines.dart b/lib/database/powersync/tables/routines.dart index cd5759642..56d962530 100644 --- a/lib/database/powersync/tables/routines.dart +++ b/lib/database/powersync/tables/routines.dart @@ -65,7 +65,7 @@ class WorkoutLogTable extends Table { TextColumn get id => text().clientDefault(() => ps.uuid.v7())(); IntColumn get exerciseId => integer().named('exercise_id')(); - IntColumn get routineId => integer().named('routine_id')(); + IntColumn get routineId => integer().named('routine_id').nullable()(); TextColumn get sessionId => text().named('session_id').nullable()(); IntColumn get iteration => integer().nullable()(); IntColumn get slotEntryId => integer().named('slot_entry_id').nullable()(); diff --git a/lib/features/routines/models/log.dart b/lib/features/routines/models/log.dart index ba72c6616..ef8475046 100644 --- a/lib/features/routines/models/log.dart +++ b/lib/features/routines/models/log.dart @@ -45,7 +45,7 @@ class Log { late int exerciseId; late Exercise exerciseObj; - late int routineId; + int? routineId; String? sessionId; int? iteration; int? slotEntryId; @@ -69,7 +69,7 @@ class Log { required this.exerciseId, this.iteration, this.slotEntryId, - required this.routineId, + this.routineId, this.sessionId, this.repetitions, this.repetitionsTarget, @@ -166,7 +166,7 @@ class Log { return WorkoutLogTableCompanion( id: id != null ? drift.Value(id!) : const drift.Value.absent(), exerciseId: drift.Value(exerciseId), - routineId: drift.Value(routineId), + routineId: routineId != null ? drift.Value(routineId) : const drift.Value.absent(), sessionId: sessionId != null ? drift.Value(sessionId) : const drift.Value.absent(), iteration: iteration != null ? drift.Value(iteration) : const drift.Value.absent(), slotEntryId: slotEntryId != null ? drift.Value(slotEntryId) : const drift.Value.absent(),