From 86f5b80177b5c1d3da2ff9fbe7694165c48ac190 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 6 Jul 2024 21:38:36 +0600 Subject: [PATCH] chore: fix insert failing to invalid conflict check --- lib/provider/authentication/authentication.dart | 2 +- lib/provider/spotify/lyrics/synced.dart | 3 ++- lib/provider/spotify/spotify.dart | 1 + lib/utils/migrations/hive.dart | 9 ++++++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/provider/authentication/authentication.dart b/lib/provider/authentication/authentication.dart index f7339ef06..05a05972c 100644 --- a/lib/provider/authentication/authentication.dart +++ b/lib/provider/authentication/authentication.dart @@ -97,7 +97,7 @@ class AuthenticationNotifier extends AsyncNotifier { await database .into(database.authenticationTable) - .insertOnConflictUpdate(refreshedCredentials); + .insert(refreshedCredentials, mode: InsertMode.replace); } Future credentialsFromCookie( diff --git a/lib/provider/spotify/lyrics/synced.dart b/lib/provider/spotify/lyrics/synced.dart index bcf2a1626..085fccb7f 100644 --- a/lib/provider/spotify/lyrics/synced.dart +++ b/lib/provider/spotify/lyrics/synced.dart @@ -152,11 +152,12 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier { } if (cachedLyrics == null || cachedLyrics.lyrics.isEmpty) { - await database.into(database.lyricsTable).insertOnConflictUpdate( + await database.into(database.lyricsTable).insert( LyricsTableCompanion.insert( trackId: track.id!, data: lyrics, ), + mode: InsertMode.replace, ); } diff --git a/lib/provider/spotify/spotify.dart b/lib/provider/spotify/spotify.dart index 63a8ed385..5997a47a6 100644 --- a/lib/provider/spotify/spotify.dart +++ b/lib/provider/spotify/spotify.dart @@ -2,6 +2,7 @@ library spotify; import 'dart:async'; +import 'package:drift/drift.dart'; import 'package:spotube/models/database/database.dart'; import 'package:spotube/provider/database/database.dart'; import 'package:spotube/provider/spotify/utils/json_cast.dart'; diff --git a/lib/utils/migrations/hive.dart b/lib/utils/migrations/hive.dart index e43df1d80..e57819314 100644 --- a/lib/utils/migrations/hive.dart +++ b/lib/utils/migrations/hive.dart @@ -35,13 +35,14 @@ Future migrateAuthenticationInfo() async { if (credentials == null) return; - await _database.into(_database.authenticationTable).insertOnConflictUpdate( + await _database.into(_database.authenticationTable).insert( AuthenticationTableCompanion.insert( accessToken: DecryptedText(credentials.accessToken), cookie: DecryptedText(credentials.cookie), expiration: credentials.expiration, id: const Value(0), ), + mode: InsertMode.insertOrReplace, ); AppLogger.log.i("✅ Migrated authentication info"); @@ -58,7 +59,7 @@ Future migratePreferences() async { if (preferences == null) return; - await _database.into(_database.preferencesTable).insertOnConflictUpdate( + await _database.into(_database.preferencesTable).insert( PreferencesTableCompanion.insert( id: const Value(0), accentColorScheme: Value(preferences.accentColorScheme), @@ -108,6 +109,7 @@ Future migratePreferences() async { systemTitleBar: Value(preferences.systemTitleBar), themeMode: Value(preferences.themeMode), ), + mode: InsertMode.replace, ); AppLogger.log.i("✅ Migrated preferences"); @@ -235,12 +237,13 @@ Future migrateLastFmCredentials() async { if (data == null) return; - await _database.into(_database.scrobblerTable).insertOnConflictUpdate( + await _database.into(_database.scrobblerTable).insert( ScrobblerTableCompanion.insert( id: const Value(0), passwordHash: DecryptedText(data.passwordHash), username: data.username, ), + mode: InsertMode.replace, ); AppLogger.log.i("✅ Migrated Last.fm credentials");