|
| 1 | +import 'package:drift/drift.dart' as drift_db; |
1 | 2 | import 'package:easy_localization/easy_localization.dart'; |
2 | 3 | import 'package:flutter/material.dart'; |
3 | 4 | import 'package:hooks_riverpod/hooks_riverpod.dart'; |
@@ -155,13 +156,36 @@ class BetaSyncSettings extends HookConsumerWidget { |
155 | 156 | title: Text("reset_sqlite".tr()), |
156 | 157 | leading: const Icon(Icons.storage), |
157 | 158 | onTap: () async { |
| 159 | + // https://github.com/simolus3/drift/commit/bd80a46264b6dd833ef4fd87fffc03f5a832ab41#diff-3f879e03b4a35779344ef16170b9353608dd9c42385f5402ec6035aac4dd8a04R76-R94 |
158 | 160 | final drift = ref.read(driftProvider); |
159 | | - // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member |
160 | | - final migrator = drift.createMigrator(); |
161 | | - for (final entity in drift.allSchemaEntities) { |
162 | | - await migrator.drop(entity); |
163 | | - await migrator.create(entity); |
164 | | - } |
| 161 | + final database = drift.attachedDatabase; |
| 162 | + await database.exclusively(() async { |
| 163 | + // https://stackoverflow.com/a/65743498/25690041 |
| 164 | + await database |
| 165 | + .customStatement('PRAGMA writable_schema = 1;'); |
| 166 | + await database |
| 167 | + .customStatement('DELETE FROM sqlite_master;'); |
| 168 | + await database.customStatement('VACUUM;'); |
| 169 | + await database |
| 170 | + .customStatement('PRAGMA writable_schema = 0;'); |
| 171 | + await database.customStatement('PRAGMA integrity_check'); |
| 172 | + |
| 173 | + await database.customStatement('PRAGMA user_version = 0'); |
| 174 | + await database.beforeOpen( |
| 175 | + // ignore: invalid_use_of_internal_member |
| 176 | + database.resolvedEngine.executor, |
| 177 | + drift_db.OpeningDetails(null, database.schemaVersion), |
| 178 | + ); |
| 179 | + await database.customStatement( |
| 180 | + 'PRAGMA user_version = ${database.schemaVersion}', |
| 181 | + ); |
| 182 | + |
| 183 | + // Refresh all stream queries |
| 184 | + database.notifyUpdates({ |
| 185 | + for (final table in database.allTables) |
| 186 | + drift_db.TableUpdate.onTable(table), |
| 187 | + }); |
| 188 | + }); |
165 | 189 | }, |
166 | 190 | ), |
167 | 191 | ], |
|
0 commit comments