Skip to content

Commit

Permalink
chore: fix insert failing to invalid conflict check
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jul 6, 2024
1 parent ccea4a0 commit 86f5b80
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/provider/authentication/authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AuthenticationNotifier extends AsyncNotifier<AuthenticationTableData?> {

await database
.into(database.authenticationTable)
.insertOnConflictUpdate(refreshedCredentials);
.insert(refreshedCredentials, mode: InsertMode.replace);
}

Future<AuthenticationTableCompanion> credentialsFromCookie(
Expand Down
3 changes: 2 additions & 1 deletion lib/provider/spotify/lyrics/synced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier<SubtitleSimple, Track?> {
}

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,
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/provider/spotify/spotify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 6 additions & 3 deletions lib/utils/migrations/hive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Future<void> 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");
Expand All @@ -58,7 +59,7 @@ Future<void> 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),
Expand Down Expand Up @@ -108,6 +109,7 @@ Future<void> migratePreferences() async {
systemTitleBar: Value(preferences.systemTitleBar),
themeMode: Value(preferences.themeMode),
),
mode: InsertMode.replace,
);

AppLogger.log.i("✅ Migrated preferences");
Expand Down Expand Up @@ -235,12 +237,13 @@ Future<void> 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");
Expand Down

0 comments on commit 86f5b80

Please sign in to comment.