From c3bb14edbf6a38992aea709a3775f1d88706ae65 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sun, 7 Dec 2025 11:26:33 +0900 Subject: [PATCH] fix temp db seed --- lib/app/state/database.dart | 78 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/lib/app/state/database.dart b/lib/app/state/database.dart index 62b98e5..e476f67 100644 --- a/lib/app/state/database.dart +++ b/lib/app/state/database.dart @@ -1,4 +1,4 @@ -import 'package:drift/drift.dart' show Value; +import 'package:drift/drift.dart' show InsertMode, Value; import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../database/database.dart'; @@ -7,45 +7,43 @@ final databaseInitializer = FutureProvider((ref) async { final db = SubtracksDatabase(); await db - .into(db.sources) - .insertOnConflictUpdate( - SourcesCompanion.insert( - id: Value(1), - name: 'test subsonic', - // isActive: Value(true), - ), - ); - await db - .into(db.subsonicSettings) - .insertOnConflictUpdate( - SubsonicSettingsCompanion.insert( - sourceId: Value(1), - address: Uri.parse('http://demo.subsonic.org'), - username: 'guest1', - password: 'guest', - useTokenAuth: Value(true), - ), - ); - await db - .into(db.sources) - .insertOnConflictUpdate( - SourcesCompanion.insert( - id: Value(2), - name: 'test navidrome', - // isActive: Value(null), - ), - ); - await db - .into(db.subsonicSettings) - .insertOnConflictUpdate( - SubsonicSettingsCompanion.insert( - sourceId: Value(2), - address: Uri.parse('http://10.0.2.2:4533'), - username: 'admin', - password: 'password', - useTokenAuth: Value(true), - ), - ); + .batch((batch) { + batch.insertAll( + db.sources, + [ + SourcesCompanion.insert( + id: Value(1), + name: 'test subsonic', + isActive: Value(true), + ), + SourcesCompanion.insert( + id: Value(2), + name: 'test navidrome', + isActive: Value(null), + ), + ], + mode: InsertMode.insertOrIgnore, + ); + batch.insertAllOnConflictUpdate(db.subsonicSettings, [ + SubsonicSettingsCompanion.insert( + sourceId: Value(1), + address: Uri.parse('http://demo.subsonic.org'), + username: 'guest1', + password: 'guest', + useTokenAuth: Value(true), + ), + SubsonicSettingsCompanion.insert( + sourceId: Value(2), + address: Uri.parse('http://10.0.2.2:4533'), + username: 'admin', + password: 'password', + useTokenAuth: Value(true), + ), + ]); + }) + .onError((error, stack) { + print(error); + }); return db; });