From f57acc08028914e00d303e5cf145c3a2393c4ada Mon Sep 17 00:00:00 2001 From: Jonathan Jogenfors Date: Tue, 10 Oct 2023 15:38:26 +0200 Subject: [PATCH] fix(server): add original path and library id index to asset (#4410) * fix: add original path index * fix: use libraryId for index, too * fix: revert openapi change --- server/src/infra/entities/asset.entity.ts | 1 + .../1696888644031-AddOriginalPathIndex.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 server/src/infra/migrations/1696888644031-AddOriginalPathIndex.ts diff --git a/server/src/infra/entities/asset.entity.ts b/server/src/infra/entities/asset.entity.ts index a2c9780ac8..31935ae5f2 100644 --- a/server/src/infra/entities/asset.entity.ts +++ b/server/src/infra/entities/asset.entity.ts @@ -31,6 +31,7 @@ export const ASSET_CHECKSUM_CONSTRAINT = 'UQ_assets_owner_library_checksum'; }) @Index('IDX_day_of_month', { synchronize: false }) @Index('IDX_month', { synchronize: false }) +@Index('IDX_originalPath_libraryId', ['originalPath', 'libraryId']) // For all assets, each originalpath must be unique per user and library export class AssetEntity { @PrimaryGeneratedColumn('uuid') diff --git a/server/src/infra/migrations/1696888644031-AddOriginalPathIndex.ts b/server/src/infra/migrations/1696888644031-AddOriginalPathIndex.ts new file mode 100644 index 0000000000..826700ffe8 --- /dev/null +++ b/server/src/infra/migrations/1696888644031-AddOriginalPathIndex.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddOriginalPathIndex1696888644031 implements MigrationInterface { + name = 'AddOriginalPathIndex1696888644031'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "IDX_originalPath_libraryId" ON "assets" ("originalPath", "libraryId")`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."IDX_originalPath_libraryId"`); + } +}