mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 17:25:11 +03:00
refactor(server): stack owner (#10900)
This commit is contained in:
22
server/src/migrations/1720207981949-AddStackOwner.ts
Normal file
22
server/src/migrations/1720207981949-AddStackOwner.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddStackOwner1720207981949 implements MigrationInterface {
|
||||
name = 'AddStackOwner1720207981949'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "asset_stack" ADD "ownerId" uuid`);
|
||||
await queryRunner.query(`
|
||||
UPDATE "asset_stack" stack
|
||||
SET "ownerId" = asset."ownerId"
|
||||
FROM "assets" asset
|
||||
WHERE stack."primaryAssetId" = asset."id"
|
||||
`)
|
||||
await queryRunner.query('ALTER TABLE "asset_stack" ALTER COLUMN "ownerId" SET NOT NULL')
|
||||
await queryRunner.query(`ALTER TABLE "asset_stack" ADD CONSTRAINT "FK_c05079e542fd74de3b5ecb5c1c8" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "asset_stack" DROP CONSTRAINT "FK_c05079e542fd74de3b5ecb5c1c8"`);
|
||||
await queryRunner.query(`ALTER TABLE "asset_stack" DROP COLUMN "ownerId"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user