store cloudId in sqlite

This commit is contained in:
shenlong-tanwen
2025-07-30 02:54:53 +05:30
parent ecbaca3cee
commit 61e079a63e
5 changed files with 36 additions and 1 deletions
@@ -16,6 +16,8 @@ class LocalAssetEntity extends Table with DriftDefaultsMixin, AssetEntityMixin {
IntColumn get orientation => integer().withDefault(const Constant(0))();
TextColumn get cloudId => text().nullable()();
@override
Set<Column> get primaryKey => {id};
}
@@ -97,6 +97,8 @@ class Drift extends $Drift implements IDatabaseRepository {
await m.create(v4.assetFaceEntity);
},
from4To5: (m, v5) async {
// Add cloudId column to local_asset_entity
await m.addColumn(v5.localAssetEntity, v5.localAssetEntity.cloudId);
await m.alterTable(
TableMigration(
v5.userEntity,
@@ -231,6 +231,25 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository {
return query.map((row) => row.readTable(_db.localAssetEntity).toDto()).get();
}
Future<void> updateCloudMapping(Map<String, String?> cloudMapping) {
if (cloudMapping.isEmpty) {
return Future.value();
}
return _db.batch((batch) {
for (final entry in cloudMapping.entries) {
final assetId = entry.key;
final cloudId = entry.value;
batch.update(
_db.localAssetEntity,
LocalAssetEntityCompanion(cloudId: Value(cloudId)),
where: (f) => f.id.equals(assetId),
);
}
});
}
Future<void> _upsertAssets(Iterable<LocalAsset> localAssets) {
if (localAssets.isEmpty) {
return Future.value();