Skip to content

Commit

Permalink
Add callback migrating database
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 29, 2023
1 parent e5e67b2 commit 84c3c69
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/src/database/hive_collections_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import 'package:matrix/matrix.dart';
import 'package:matrix/src/utils/queued_to_device_event.dart';
import 'package:matrix/src/utils/run_benchmarked.dart';

typedef StartMigrationProcess = Function();

/// This database does not support file caching!
class HiveCollectionsDatabase extends DatabaseApi {
static const int version = 6;
final String name;
final String? path;
final HiveCipher? key;
final StartMigrationProcess? startMigrationProcess;
final Future<BoxCollection> Function(
String name,
Set<String> boxNames, {
Expand Down Expand Up @@ -127,7 +130,8 @@ class HiveCollectionsDatabase extends DatabaseApi {

HiveCollectionsDatabase(
this.name,
this.path, {
this.path,{
this.startMigrationProcess,
this.key,
this.collectionFactory = BoxCollection.open,
});
Expand Down Expand Up @@ -238,6 +242,9 @@ class HiveCollectionsDatabase extends DatabaseApi {

Future<void> _migrateFromVersion(int currentVersion) async {
Logs().i('Migrate store database from version $currentVersion to $version');
if (startMigrationProcess != null) {
startMigrationProcess!.call();
}
await clearCache();
await _clientBox.put('version', version.toString());
}
Expand Down

0 comments on commit 84c3c69

Please sign in to comment.