handle cloud id migration

This commit is contained in:
shenlong-tanwen
2025-09-04 01:27:34 +05:30
parent d02d3b5472
commit 82c93cf325
7 changed files with 139 additions and 28 deletions
+1 -25
View File
@@ -35,7 +35,7 @@ import 'package:logging/logging.dart';
// ignore: import_rule_photo_manager
import 'package:photo_manager/photo_manager.dart';
const int targetVersion = 15;
const int targetVersion = 14;
Future<void> migrateDatabaseIfNeeded(Isar db, Drift drift) async {
final hasVersion = Store.tryGet(StoreKey.version) != null;
@@ -70,16 +70,6 @@ Future<void> migrateDatabaseIfNeeded(Isar db, Drift drift) async {
await Store.populateCache();
}
if (version < 15) {
try {
await updateCloudId(drift);
} catch (error) {
Logger("Migration").warning("Error occurred while updating cloud ID: $error");
// do not update version when error occurs so this is retried the next time
return;
}
}
if (targetVersion >= 12) {
await Store.put(StoreKey.version, targetVersion);
return;
@@ -189,20 +179,6 @@ Future<void> migrateDeviceAssetToSqlite(Isar db, Drift drift) async {
}
}
Future<void> updateCloudId(Drift drift) async {
// Android do not have a concept of cloud IDs
if (Platform.isAndroid) {
return;
}
final query = drift.localAssetEntity.selectOnly()
..addColumns([drift.localAssetEntity.id])
..where(drift.localAssetEntity.cloudId.isNull());
final ids = await query.map((row) => row.read(drift.localAssetEntity.id)!).get();
final cloudMapping = await NativeSyncApi().getCloudIdForAssetIds(ids);
await DriftLocalAlbumRepository(drift).updateCloudMapping(cloudMapping);
}
Future<void> migrateBackupAlbumsToSqlite(Isar db, Drift drift) async {
try {
final isarBackupAlbums = await db.backupAlbums.where().findAll();