From 3fe421676c0ed1aad66d418b47ba524d3da2ae7d Mon Sep 17 00:00:00 2001 From: Mathis Kirchner Date: Mon, 9 Mar 2026 15:29:18 +0100 Subject: [PATCH] update onDelete behavior for groupId in match_table to set null --- lib/data/db/database.g.dart | 4 ++-- lib/data/db/tables/match_table.dart | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/data/db/database.g.dart b/lib/data/db/database.g.dart index fe14e93..227c7c0 100644 --- a/lib/data/db/database.g.dart +++ b/lib/data/db/database.g.dart @@ -1123,7 +1123,7 @@ class $MatchTableTable extends MatchTable type: DriftSqlType.string, requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways( - 'REFERENCES group_table (id) ON DELETE CASCADE', + 'REFERENCES group_table (id) ON DELETE SET NULL', ), ); static const VerificationMeta _nameMeta = const VerificationMeta('name'); @@ -2780,7 +2780,7 @@ abstract class _$AppDatabase extends GeneratedDatabase { 'group_table', limitUpdateKind: UpdateKind.delete, ), - result: [TableUpdate('match_table', kind: UpdateKind.delete)], + result: [TableUpdate('match_table', kind: UpdateKind.update)], ), WritePropagation( on: TableUpdateQuery.onTableName( diff --git a/lib/data/db/tables/match_table.dart b/lib/data/db/tables/match_table.dart index 191e72c..545b133 100644 --- a/lib/data/db/tables/match_table.dart +++ b/lib/data/db/tables/match_table.dart @@ -7,8 +7,10 @@ class MatchTable extends Table { TextColumn get gameId => text().references(GameTable, #id, onDelete: KeyAction.cascade)(); // Nullable if there is no group associated with the match - TextColumn get groupId => - text().references(GroupTable, #id, onDelete: KeyAction.cascade).nullable()(); + // onDelete: If a group gets deleted, groupId in the match gets set to null + TextColumn get groupId => text() + .references(GroupTable, #id, onDelete: KeyAction.setNull) + .nullable()(); TextColumn get name => text().nullable()(); TextColumn get notes => text().nullable()(); DateTimeColumn get createdAt => dateTime()(); @@ -16,4 +18,4 @@ class MatchTable extends Table { @override Set> get primaryKey => {id}; -} \ No newline at end of file +}