From 118b316a359f53fc5f5b22e2610f574b4ec1f91c Mon Sep 17 00:00:00 2001 From: gelbeinhalb Date: Fri, 23 Jan 2026 11:25:20 +0100 Subject: [PATCH] description is now a required game parameter --- lib/data/dao/game_dao.dart | 6 ++-- lib/data/dao/match_dao.dart | 2 +- lib/data/db/database.dart | 2 +- lib/data/db/database.g.dart | 43 ++++++++++++++-------------- lib/data/db/tables/game_table.dart | 2 +- lib/data/dto/game.dart | 4 +-- test/db_tests/game_test.dart | 14 ++++----- test/db_tests/match_test.dart | 2 +- test/db_tests/player_match_test.dart | 2 +- test/db_tests/score_test.dart | 2 +- test/db_tests/team_test.dart | 4 +-- 11 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/data/dao/game_dao.dart b/lib/data/dao/game_dao.dart index 1d8af98..62db351 100644 --- a/lib/data/dao/game_dao.dart +++ b/lib/data/dao/game_dao.dart @@ -53,7 +53,7 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { id: game.id, name: game.name, ruleset: game.ruleset ?? '', - description: Value(game.description), + description: game.description, color: game.color, icon: Value(game.icon), createdAt: game.createdAt, @@ -79,7 +79,7 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { id: game.id, name: game.name, ruleset: game.ruleset ?? '', - description: Value(game.description), + description: game.description, color: game.color, icon: Value(game.icon), createdAt: game.createdAt, @@ -132,7 +132,7 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { /// Updates the description of the game with the given [gameId]. Future updateGameDescription({ required String gameId, - required String? newDescription, + required String newDescription, }) async { await (update(gameTable)..where((g) => g.id.equals(gameId))).write( GameTableCompanion(description: Value(newDescription)), diff --git a/lib/data/dao/match_dao.dart b/lib/data/dao/match_dao.dart index af6d602..3d5efb0 100644 --- a/lib/data/dao/match_dao.dart +++ b/lib/data/dao/match_dao.dart @@ -128,7 +128,7 @@ class MatchDao extends DatabaseAccessor with _$MatchDaoMixin { id: game.id, name: game.name, ruleset: game.ruleset ?? '', - description: Value(game.description), + description: game.description, color: game.color, icon: Value(game.icon), createdAt: game.createdAt, diff --git a/lib/data/db/database.dart b/lib/data/db/database.dart index 628e013..d3d447c 100644 --- a/lib/data/db/database.dart +++ b/lib/data/db/database.dart @@ -46,7 +46,7 @@ class AppDatabase extends _$AppDatabase { AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection()); @override - int get schemaVersion => 2; + int get schemaVersion => 1; @override MigrationStrategy get migration { diff --git a/lib/data/db/database.g.dart b/lib/data/db/database.g.dart index a2d99c1..3faa308 100644 --- a/lib/data/db/database.g.dart +++ b/lib/data/db/database.g.dart @@ -673,9 +673,9 @@ class $GameTableTable extends GameTable late final GeneratedColumn description = GeneratedColumn( 'description', aliasedName, - true, + false, type: DriftSqlType.string, - requiredDuringInsert: false, + requiredDuringInsert: true, ); static const VerificationMeta _colorMeta = const VerificationMeta('color'); @override @@ -757,6 +757,8 @@ class $GameTableTable extends GameTable _descriptionMeta, ), ); + } else if (isInserting) { + context.missing(_descriptionMeta); } if (data.containsKey('color')) { context.handle( @@ -804,7 +806,7 @@ class $GameTableTable extends GameTable description: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}description'], - ), + )!, color: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}color'], @@ -830,7 +832,7 @@ class GameTableData extends DataClass implements Insertable { final String id; final String name; final String ruleset; - final String? description; + final String description; final String color; final String? icon; final DateTime createdAt; @@ -838,7 +840,7 @@ class GameTableData extends DataClass implements Insertable { required this.id, required this.name, required this.ruleset, - this.description, + required this.description, required this.color, this.icon, required this.createdAt, @@ -849,9 +851,7 @@ class GameTableData extends DataClass implements Insertable { map['id'] = Variable(id); map['name'] = Variable(name); map['ruleset'] = Variable(ruleset); - if (!nullToAbsent || description != null) { - map['description'] = Variable(description); - } + map['description'] = Variable(description); map['color'] = Variable(color); if (!nullToAbsent || icon != null) { map['icon'] = Variable(icon); @@ -865,9 +865,7 @@ class GameTableData extends DataClass implements Insertable { id: Value(id), name: Value(name), ruleset: Value(ruleset), - description: description == null && nullToAbsent - ? const Value.absent() - : Value(description), + description: Value(description), color: Value(color), icon: icon == null && nullToAbsent ? const Value.absent() : Value(icon), createdAt: Value(createdAt), @@ -883,7 +881,7 @@ class GameTableData extends DataClass implements Insertable { id: serializer.fromJson(json['id']), name: serializer.fromJson(json['name']), ruleset: serializer.fromJson(json['ruleset']), - description: serializer.fromJson(json['description']), + description: serializer.fromJson(json['description']), color: serializer.fromJson(json['color']), icon: serializer.fromJson(json['icon']), createdAt: serializer.fromJson(json['createdAt']), @@ -896,7 +894,7 @@ class GameTableData extends DataClass implements Insertable { 'id': serializer.toJson(id), 'name': serializer.toJson(name), 'ruleset': serializer.toJson(ruleset), - 'description': serializer.toJson(description), + 'description': serializer.toJson(description), 'color': serializer.toJson(color), 'icon': serializer.toJson(icon), 'createdAt': serializer.toJson(createdAt), @@ -907,7 +905,7 @@ class GameTableData extends DataClass implements Insertable { String? id, String? name, String? ruleset, - Value description = const Value.absent(), + String? description, String? color, Value icon = const Value.absent(), DateTime? createdAt, @@ -915,7 +913,7 @@ class GameTableData extends DataClass implements Insertable { id: id ?? this.id, name: name ?? this.name, ruleset: ruleset ?? this.ruleset, - description: description.present ? description.value : this.description, + description: description ?? this.description, color: color ?? this.color, icon: icon.present ? icon.value : this.icon, createdAt: createdAt ?? this.createdAt, @@ -968,7 +966,7 @@ class GameTableCompanion extends UpdateCompanion { final Value id; final Value name; final Value ruleset; - final Value description; + final Value description; final Value color; final Value icon; final Value createdAt; @@ -987,7 +985,7 @@ class GameTableCompanion extends UpdateCompanion { required String id, required String name, required String ruleset, - this.description = const Value.absent(), + required String description, required String color, this.icon = const Value.absent(), required DateTime createdAt, @@ -995,6 +993,7 @@ class GameTableCompanion extends UpdateCompanion { }) : id = Value(id), name = Value(name), ruleset = Value(ruleset), + description = Value(description), color = Value(color), createdAt = Value(createdAt); static Insertable custom({ @@ -1023,7 +1022,7 @@ class GameTableCompanion extends UpdateCompanion { Value? id, Value? name, Value? ruleset, - Value? description, + Value? description, Value? color, Value? icon, Value? createdAt, @@ -3663,7 +3662,7 @@ typedef $$GameTableTableCreateCompanionBuilder = required String id, required String name, required String ruleset, - Value description, + required String description, required String color, Value icon, required DateTime createdAt, @@ -3674,7 +3673,7 @@ typedef $$GameTableTableUpdateCompanionBuilder = Value id, Value name, Value ruleset, - Value description, + Value description, Value color, Value icon, Value createdAt, @@ -3908,7 +3907,7 @@ class $$GameTableTableTableManager Value id = const Value.absent(), Value name = const Value.absent(), Value ruleset = const Value.absent(), - Value description = const Value.absent(), + Value description = const Value.absent(), Value color = const Value.absent(), Value icon = const Value.absent(), Value createdAt = const Value.absent(), @@ -3928,7 +3927,7 @@ class $$GameTableTableTableManager required String id, required String name, required String ruleset, - Value description = const Value.absent(), + required String description, required String color, Value icon = const Value.absent(), required DateTime createdAt, diff --git a/lib/data/db/tables/game_table.dart b/lib/data/db/tables/game_table.dart index eaa3e1b..ce71a59 100644 --- a/lib/data/db/tables/game_table.dart +++ b/lib/data/db/tables/game_table.dart @@ -4,7 +4,7 @@ class GameTable extends Table { TextColumn get id => text()(); TextColumn get name => text()(); TextColumn get ruleset => text()(); - TextColumn get description => text().nullable()(); + TextColumn get description => text()(); TextColumn get color => text()(); TextColumn get icon => text().nullable()(); DateTimeColumn get createdAt => dateTime()(); diff --git a/lib/data/dto/game.dart b/lib/data/dto/game.dart index 5afbd9b..c63bdea 100644 --- a/lib/data/dto/game.dart +++ b/lib/data/dto/game.dart @@ -6,7 +6,7 @@ class Game { final DateTime createdAt; final String name; final String? ruleset; - final String? description; + final String description; final String color; final String? icon; @@ -15,7 +15,7 @@ class Game { DateTime? createdAt, required this.name, this.ruleset, - this.description, + required this.description, required this.color, this.icon, }) : id = id ?? const Uuid().v4(), diff --git a/test/db_tests/game_test.dart b/test/db_tests/game_test.dart index 250d67a..4182530 100644 --- a/test/db_tests/game_test.dart +++ b/test/db_tests/game_test.dart @@ -131,7 +131,7 @@ void main() { // Verifies that a game with null optional fields can be added and retrieved. test('addGame handles game with null optional fields', () async { - final gameWithNulls = Game(name: 'Simple Game', color: '0xFF000000'); + final gameWithNulls = Game(name: 'Simple Game', description: 'A simple game', color: '0xFF000000'); final result = await database.gameDao.addGame(game: gameWithNulls); expect(result, true); @@ -139,7 +139,7 @@ void main() { gameId: gameWithNulls.id, ); expect(fetchedGame.name, 'Simple Game'); - expect(fetchedGame.description, isNull); + expect(fetchedGame.description, 'A simple game'); expect(fetchedGame.color, '0xFF000000'); expect(fetchedGame.icon, isNull); }); @@ -305,19 +305,19 @@ void main() { expect(updatedGame.description, 'An updated description'); }); - // Verifies that updateGameDescription can set the description to null. - test('updateGameDescription can set description to null', () async { + // Verifies that updateGameDescription can set the description to an empty string. + test('updateGameDescription can set description to empty string', () async { await database.gameDao.addGame(game: testGame1); await database.gameDao.updateGameDescription( gameId: testGame1.id, - newDescription: null, + newDescription: '', ); final updatedGame = await database.gameDao.getGameById( gameId: testGame1.id, ); - expect(updatedGame.description, isNull); + expect(updatedGame.description, ''); }); // Verifies that updateGameDescription does nothing when game doesn't exist. @@ -502,7 +502,7 @@ void main() { gameId: longGame.id, ); expect(fetchedGame.name.length, 10000); - expect(fetchedGame.description?.length, 10000); + expect(fetchedGame.description.length, 10000); expect(fetchedGame.ruleset?.length, 10000); }); diff --git a/test/db_tests/match_test.dart b/test/db_tests/match_test.dart index 055efad..f5d3fb2 100644 --- a/test/db_tests/match_test.dart +++ b/test/db_tests/match_test.dart @@ -48,7 +48,7 @@ void main() { name: 'Test Group 2', members: [testPlayer4, testPlayer5], ); - testGame = Game(name: 'Test Game', color: '0xFF000000'); + testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000'); testMatch1 = Match( name: 'First Test Match', game: testGame, diff --git a/test/db_tests/player_match_test.dart b/test/db_tests/player_match_test.dart index 899857e..3758e0b 100644 --- a/test/db_tests/player_match_test.dart +++ b/test/db_tests/player_match_test.dart @@ -46,7 +46,7 @@ void main() { name: 'Test Group', members: [testPlayer1, testPlayer2, testPlayer3], ); - testGame = Game(name: 'Test Game', color: '0xFF000000'); + testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000'); testMatchOnlyGroup = Match( name: 'Test Match with Group', game: testGame, diff --git a/test/db_tests/score_test.dart b/test/db_tests/score_test.dart index 5ddaade..bc9d536 100644 --- a/test/db_tests/score_test.dart +++ b/test/db_tests/score_test.dart @@ -31,7 +31,7 @@ void main() { testPlayer1 = Player(name: 'Alice'); testPlayer2 = Player(name: 'Bob'); testPlayer3 = Player(name: 'Charlie'); - testGame = Game(name: 'Test Game', color: '0xFF000000'); + testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000'); testMatch1 = Match( name: 'Test Match 1', game: testGame, diff --git a/test/db_tests/team_test.dart b/test/db_tests/team_test.dart index 72c1adc..84188a0 100644 --- a/test/db_tests/team_test.dart +++ b/test/db_tests/team_test.dart @@ -48,8 +48,8 @@ void main() { name: 'Team Gamma', members: [testPlayer1, testPlayer3], ); - testGame1 = Game(name: 'Game 1', color: '0xFF000000'); - testGame2 = Game(name: 'Game 2', color: '0xFF000000'); + testGame1 = Game(name: 'Game 1', description: 'Test game 1', color: '0xFF000000'); + testGame2 = Game(name: 'Game 2', description: 'Test game 2', color: '0xFF000000'); }); await database.playerDao.addPlayersAsList(