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: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/entities/user.entity.dart';
|
||||||
import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart';
|
import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart';
|
||||||
|
|
||||||
|
|
@ -15,7 +14,7 @@ class StackEntity extends Table with DriftDefaultsMixin {
|
||||||
TextColumn get ownerId =>
|
TextColumn get ownerId =>
|
||||||
text().references(UserEntity, #id, onDelete: KeyAction.cascade)();
|
text().references(UserEntity, #id, onDelete: KeyAction.cascade)();
|
||||||
|
|
||||||
TextColumn get primaryAssetId => text().references(RemoteAssetEntity, #id)();
|
TextColumn get primaryAssetId => text()();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Set<Column> get primaryKey => {id};
|
Set<Column> get primaryKey => {id};
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -72,7 +72,7 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 2;
|
int get schemaVersion => 3;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
MigrationStrategy get migration => MigrationStrategy(
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
|
|
@ -84,12 +84,16 @@ class Drift extends $Drift implements IDatabaseRepository {
|
||||||
from: from,
|
from: from,
|
||||||
to: to,
|
to: to,
|
||||||
steps: migrationSteps(
|
steps: migrationSteps(
|
||||||
from1To2: (m, _) async {
|
from1To2: (m, v2) async {
|
||||||
for (final entity in allSchemaEntities) {
|
for (final entity in v2.entities) {
|
||||||
await m.drop(entity);
|
await m.drop(entity);
|
||||||
await m.create(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) {
|
Future<void> stack(String userId, StackResponse stack) {
|
||||||
return _db.transaction(() async {
|
return _db.transaction(() async {
|
||||||
final stackIds = await _db.managers.stackEntity
|
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)
|
.map((row) => row.id)
|
||||||
.get();
|
.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