mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 09:38:43 +03:00
fix: reset sqlite on beta migration (#20735)
reset sync stream on migration Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
@@ -69,6 +69,29 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||
Drift([QueryExecutor? executor])
|
||||
: super(executor ?? driftDatabase(name: 'immich', native: const DriftNativeOptions(shareAcrossIsolates: true)));
|
||||
|
||||
Future<void> reset() async {
|
||||
// https://github.com/simolus3/drift/commit/bd80a46264b6dd833ef4fd87fffc03f5a832ab41#diff-3f879e03b4a35779344ef16170b9353608dd9c42385f5402ec6035aac4dd8a04R76-R94
|
||||
await exclusively(() async {
|
||||
// https://stackoverflow.com/a/65743498/25690041
|
||||
await customStatement('PRAGMA writable_schema = 1;');
|
||||
await customStatement('DELETE FROM sqlite_master;');
|
||||
await customStatement('VACUUM;');
|
||||
await customStatement('PRAGMA writable_schema = 0;');
|
||||
await customStatement('PRAGMA integrity_check');
|
||||
|
||||
await customStatement('PRAGMA user_version = 0');
|
||||
await beforeOpen(
|
||||
// ignore: invalid_use_of_internal_member
|
||||
resolvedEngine.executor,
|
||||
OpeningDetails(null, schemaVersion),
|
||||
);
|
||||
await customStatement('PRAGMA user_version = $schemaVersion');
|
||||
|
||||
// Refresh all stream queries
|
||||
notifyUpdates({for (final table in allTables) TableUpdate.onTable(table)});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
int get schemaVersion => 10;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user