2023-03-22 18:36:44 -07:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-03-26 19:35:52 -07:00
|
|
|
import 'package:immich_mobile/utils/db.dart';
|
2023-03-18 07:55:11 -07:00
|
|
|
import 'package:isar/isar.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
|
2023-03-26 19:35:52 -07:00
|
|
|
Future<void> migrateDatabaseIfNeeded(Isar db) async {
|
|
|
|
final int version = Store.get(StoreKey.version, 1);
|
|
|
|
switch (version) {
|
|
|
|
case 1:
|
2023-06-10 11:13:59 -07:00
|
|
|
await _migrateTo(db, 2);
|
|
|
|
case 2:
|
|
|
|
await _migrateTo(db, 3);
|
2023-03-26 19:35:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 11:13:59 -07:00
|
|
|
Future<void> _migrateTo(Isar db, int version) async {
|
2023-03-26 19:35:52 -07:00
|
|
|
await clearAssetsAndAlbums(db);
|
2023-06-10 11:13:59 -07:00
|
|
|
await Store.put(StoreKey.version, version);
|
2023-03-26 19:35:52 -07:00
|
|
|
}
|