chore: catch migration error (#19096)

This commit is contained in:
Alex 2025-06-10 10:21:36 -05:00 committed by GitHub
parent 4b4ee5abf3
commit b50d9fa448
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -166,25 +166,33 @@ Future<void> _migrateDeviceAsset(Isar db) async {
}
Future<void> _migrateDeviceAssetToSqlite(Isar db, Drift drift) async {
final isarDeviceAssets =
await db.deviceAssetEntitys.where().sortByAssetId().findAll();
await drift.batch((batch) {
for (final deviceAsset in isarDeviceAssets) {
final companion = LocalAssetEntityCompanion(
updatedAt: Value(deviceAsset.modifiedTime),
id: Value(deviceAsset.assetId),
checksum: Value(base64.encode(deviceAsset.hash)),
);
batch.insert<$LocalAssetEntityTable, LocalAssetEntityData>(
drift.localAssetEntity,
companion,
onConflict: DoUpdate(
(_) => companion,
where: (old) => old.updatedAt.equals(deviceAsset.modifiedTime),
),
try {
final isarDeviceAssets =
await db.deviceAssetEntitys.where().sortByAssetId().findAll();
await drift.batch((batch) {
for (final deviceAsset in isarDeviceAssets) {
final companion = LocalAssetEntityCompanion(
updatedAt: Value(deviceAsset.modifiedTime),
id: Value(deviceAsset.assetId),
checksum: Value(base64.encode(deviceAsset.hash)),
);
batch.insert<$LocalAssetEntityTable, LocalAssetEntityData>(
drift.localAssetEntity,
companion,
onConflict: DoUpdate(
(_) => companion,
where: (old) => old.updatedAt.equals(deviceAsset.modifiedTime),
),
);
}
});
} catch (error) {
if (kDebugMode) {
debugPrint(
"[MIGRATION] Error while migrating device assets to SQLite: $error",
);
}
});
}
}
class _DeviceAsset {