Skip to content

Commit f1c494e

Browse files
fix: use create if not exists clause for indexes (#20728)
Co-authored-by: shenlong-tanwen <[email protected]>
1 parent 9c8c528 commit f1c494e

File tree

10 files changed

+22
-17
lines changed

10 files changed

+22
-17
lines changed

mobile/drift_schemas/main/drift_schema_v7.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/lib/infrastructure/entities/exif.entity.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ExifInfo {
9595
);
9696
}
9797

98-
@TableIndex(name: 'idx_lat_lng', columns: {#latitude, #longitude})
98+
@TableIndex.sql('CREATE INDEX IF NOT EXISTS idx_lat_lng ON remote_exif_entity (latitude, longitude)')
9999
class RemoteExifEntity extends Table with DriftDefaultsMixin {
100100
const RemoteExifEntity();
101101

mobile/lib/infrastructure/entities/exif.entity.drift.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/lib/infrastructure/entities/local_asset.entity.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:immich_mobile/infrastructure/entities/local_asset.entity.drift.d
44
import 'package:immich_mobile/infrastructure/utils/asset.mixin.dart';
55
import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart';
66

7-
@TableIndex(name: 'idx_local_asset_checksum', columns: {#checksum})
7+
@TableIndex.sql('CREATE INDEX IF NOT EXISTS idx_local_asset_checksum ON local_asset_entity (checksum)')
88
class LocalAssetEntity extends Table with DriftDefaultsMixin, AssetEntityMixin {
99
const LocalAssetEntity();
1010

mobile/lib/infrastructure/entities/local_asset.entity.drift.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/lib/infrastructure/entities/remote_asset.entity.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import 'package:immich_mobile/infrastructure/entities/user.entity.dart';
55
import 'package:immich_mobile/infrastructure/utils/asset.mixin.dart';
66
import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart';
77

8-
@TableIndex(name: 'idx_remote_asset_owner_checksum', columns: {#ownerId, #checksum})
8+
@TableIndex.sql(
9+
'CREATE INDEX IF NOT EXISTS idx_remote_asset_owner_checksum ON remote_asset_entity (owner_id, checksum)',
10+
)
911
@TableIndex.sql('''
1012
CREATE UNIQUE INDEX IF NOT EXISTS UQ_remote_assets_owner_checksum
1113
ON remote_asset_entity (owner_id, checksum)
@@ -16,7 +18,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS UQ_remote_assets_owner_library_checksum
1618
ON remote_asset_entity (owner_id, library_id, checksum)
1719
WHERE (library_id IS NOT NULL);
1820
''')
19-
@TableIndex(name: 'idx_remote_asset_checksum', columns: {#checksum})
21+
@TableIndex.sql('CREATE INDEX IF NOT EXISTS idx_remote_asset_checksum ON remote_asset_entity (checksum)')
2022
class RemoteAssetEntity extends Table with DriftDefaultsMixin, AssetEntityMixin {
2123
const RemoteAssetEntity();
2224

mobile/lib/infrastructure/entities/remote_asset.entity.drift.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/lib/infrastructure/repositories/db.repository.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ class Drift extends $Drift implements IDatabaseRepository {
106106
from5To6: (m, v6) async {
107107
// Drops the (checksum, ownerId) and adds it back as (ownerId, checksum)
108108
await customStatement('DROP INDEX IF EXISTS UQ_remote_asset_owner_checksum');
109+
await m.drop(v6.idxRemoteAssetOwnerChecksum);
109110
await m.create(v6.idxRemoteAssetOwnerChecksum);
110111
// Adds libraryId to remote_asset_entity
111112
await m.addColumn(v6.remoteAssetEntity, v6.remoteAssetEntity.libraryId);
113+
await m.drop(v6.uQRemoteAssetsOwnerChecksum);
112114
await m.create(v6.uQRemoteAssetsOwnerChecksum);
115+
await m.drop(v6.uQRemoteAssetsOwnerLibraryChecksum);
113116
await m.create(v6.uQRemoteAssetsOwnerLibraryChecksum);
114117
},
115118
from6To7: (m, v7) async {

mobile/lib/infrastructure/repositories/db.repository.steps.dart

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/test/drift/main/generated/schema_v7.dart

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)