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

View File

@@ -95,6 +95,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
}
// Insert unique groups in batch
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group associations when groups already exist
await db.batch(
(b) => b.insertAll(
groupTable,
@@ -107,7 +109,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
),
)
.toList(),
mode: InsertMode.insertOrReplace,
mode: InsertMode.insertOrIgnore,
),
);
@@ -120,6 +122,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
}
if (uniquePlayers.isNotEmpty) {
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group associations when players already exist
await db.batch(
(b) => b.insertAll(
db.playerTable,
@@ -132,7 +136,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
),
)
.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
// Using insertOrIgnore to avoid overwriting existing groups (which would
// trigger cascade deletes on player_group associations)
await db.batch(
(b) => b.insertAll(
db.groupTable,
@@ -137,7 +139,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
),
)
.toList(),
mode: InsertMode.insertOrReplace,
mode: InsertMode.insertOrIgnore,
),
);
@@ -158,6 +160,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
}
if (uniquePlayers.isNotEmpty) {
// Using insertOrIgnore to avoid triggering cascade deletes on
// player_group/player_match associations when players already exist
await db.batch(
(b) => b.insertAll(
db.playerTable,
@@ -170,7 +174,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
),
)
.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.
/// Uses insertOrIgnore to avoid triggering cascade deletes on
/// player_group associations when players already exist.
Future<bool> addPlayersAsList({required List<Player> players}) async {
if (players.isEmpty) return false;
@@ -65,7 +67,7 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
),
)
.toList(),
mode: InsertMode.insertOrReplace,
mode: InsertMode.insertOrIgnore,
),
);