mirror of
https://github.com/samsonjs/immich.git
synced 2026-03-25 09:15:56 +00:00
fix: remove foreign constraint on stack.primaryAssetId (#20052)
* fix: remove foreign constraint in stack.primaryAssetId * fix migration --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
5fc4393e7a
commit
1dc62fce5f
8 changed files with 9 additions and 6 deletions
BIN
mobile/drift_schemas/main/drift_schema_v3.json
generated
Normal file
BIN
mobile/drift_schemas/main/drift_schema_v3.json
generated
Normal file
Binary file not shown.
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:drift/drift.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/remote_asset.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/entities/user.entity.dart';
|
||||
import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart';
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ class StackEntity extends Table with DriftDefaultsMixin {
|
|||
TextColumn get ownerId =>
|
||||
text().references(UserEntity, #id, onDelete: KeyAction.cascade)();
|
||||
|
||||
TextColumn get primaryAssetId => text().references(RemoteAssetEntity, #id)();
|
||||
TextColumn get primaryAssetId => text()();
|
||||
|
||||
@override
|
||||
Set<Column> get primaryKey => {id};
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -72,7 +72,7 @@ class Drift extends $Drift implements IDatabaseRepository {
|
|||
);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 2;
|
||||
int get schemaVersion => 3;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
|
|
@ -84,12 +84,16 @@ class Drift extends $Drift implements IDatabaseRepository {
|
|||
from: from,
|
||||
to: to,
|
||||
steps: migrationSteps(
|
||||
from1To2: (m, _) async {
|
||||
for (final entity in allSchemaEntities) {
|
||||
from1To2: (m, v2) async {
|
||||
for (final entity in v2.entities) {
|
||||
await m.drop(entity);
|
||||
await m.create(entity);
|
||||
}
|
||||
},
|
||||
from2To3: (m, v3) async {
|
||||
// Removed foreign key constraint on stack.primaryAssetId
|
||||
await m.alterTable(TableMigration(v3.stackEntity));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -193,7 +193,7 @@ class RemoteAssetRepository extends DriftDatabaseRepository {
|
|||
Future<void> stack(String userId, StackResponse stack) {
|
||||
return _db.transaction(() async {
|
||||
final stackIds = await _db.managers.stackEntity
|
||||
.filter((row) => row.primaryAssetId.id.isIn(stack.assetIds))
|
||||
.filter((row) => row.primaryAssetId.isIn(stack.assetIds))
|
||||
.map((row) => row.id)
|
||||
.get();
|
||||
|
||||
|
|
|
|||
Binary file not shown.
BIN
mobile/test/drift/main/generated/schema_v3.dart
Normal file
BIN
mobile/test/drift/main/generated/schema_v3.dart
Normal file
Binary file not shown.
Loading…
Reference in a new issue