3 Commits

Author SHA1 Message Date
gelbeinhalb
2fea3597fe Merge branch 'enhancement/70-konsistenzfehler-im-json-vermeiden' of git.yannick-weigert.de:liquid-development/game-tracker into enhancement/70-konsistenzfehler-im-json-vermeiden
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m3s
Pull Request Pipeline / lint (pull_request) Successful in 2m6s
2026-01-05 11:46:34 +01:00
gelbeinhalb
7b2314a25e fix null error for winnerId and groupId in match import 2026-01-05 11:46:26 +01:00
gelbeinhalb
7f6c1cb9a6 change InsertMode to insertOrIgnore not insertOrReplace 2026-01-05 11:40:57 +01:00
4 changed files with 24 additions and 9 deletions

View File

@@ -68,7 +68,10 @@
"type": "string" "type": "string"
}, },
"groupId": { "groupId": {
"type": "string" "anyOf": [
{"type": "string"},
{"type": "null"}
]
}, },
"playerIds": { "playerIds": {
"type": "array", "type": "array",
@@ -77,7 +80,10 @@
} }
}, },
"winnerId": { "winnerId": {
"type": "string" "anyOf": [
{"type": "string"},
{"type": "null"}
]
} }
}, },
"required": [ "required": [
@@ -85,8 +91,7 @@
"name", "name",
"createdAt", "createdAt",
"groupId", "groupId",
"playerIds", "playerIds"
"winnerId"
] ]
} }
} }

View File

@@ -95,6 +95,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
} }
// Insert unique groups in batch // Insert unique groups in batch
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group associations when groups already exist
await db.batch( await db.batch(
(b) => b.insertAll( (b) => b.insertAll(
groupTable, groupTable,
@@ -107,7 +109,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
), ),
) )
.toList(), .toList(),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
), ),
); );
@@ -120,6 +122,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
} }
if (uniquePlayers.isNotEmpty) { if (uniquePlayers.isNotEmpty) {
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group associations when players already exist
await db.batch( await db.batch(
(b) => b.insertAll( (b) => b.insertAll(
db.playerTable, db.playerTable,
@@ -132,7 +136,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
), ),
) )
.toList(), .toList(),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
), ),
); );
} }

View File

@@ -124,6 +124,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
// Add all groups of the matches in batch // Add all groups of the matches in batch
// Using insertOrIgnore to avoid overwriting existing groups (which would
// trigger cascade deletes on player_group associations)
await db.batch( await db.batch(
(b) => b.insertAll( (b) => b.insertAll(
db.groupTable, db.groupTable,
@@ -137,7 +139,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
), ),
) )
.toList(), .toList(),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
), ),
); );
@@ -158,6 +160,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
} }
if (uniquePlayers.isNotEmpty) { if (uniquePlayers.isNotEmpty) {
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group/player_match associations when players already exist
await db.batch( await db.batch(
(b) => b.insertAll( (b) => b.insertAll(
db.playerTable, db.playerTable,
@@ -170,7 +174,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
), ),
) )
.toList(), .toList(),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
), ),
); );
} }

View File

@@ -50,6 +50,8 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
} }
/// Adds multiple [players] to the database in a batch operation. /// Adds multiple [players] to the database in a batch operation.
/// Uses insertOrIgnore to avoid triggering cascade deletes on
/// player_group associations when players already exist.
Future<bool> addPlayersAsList({required List<Player> players}) async { Future<bool> addPlayersAsList({required List<Player> players}) async {
if (players.isEmpty) return false; if (players.isEmpty) return false;
@@ -65,7 +67,7 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
), ),
) )
.toList(), .toList(),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrIgnore,
), ),
); );