From 8322af0baf2be8d59f868db9868b9694f999e615 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:54:08 -0400 Subject: [PATCH] simplify --- .../1718486162779-AddFaceSearchRelation.ts | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/server/src/migrations/1718486162779-AddFaceSearchRelation.ts b/server/src/migrations/1718486162779-AddFaceSearchRelation.ts index 289b6c9c8c..e4ed38e9df 100644 --- a/server/src/migrations/1718486162779-AddFaceSearchRelation.ts +++ b/server/src/migrations/1718486162779-AddFaceSearchRelation.ts @@ -9,26 +9,22 @@ export class AddFaceSearchRelation1718486162779 implements MigrationInterface { await queryRunner.query(`SET vectors.pgvector_compatibility=on`); } + await queryRunner.query(`ALTER TABLE asset_faces ADD COLUMN IF NOT EXISTS embedding vector(512)`); + await queryRunner.query(`ALTER TABLE smart_search ADD COLUMN IF NOT EXISTS embedding vector(512) NOT NULL`); + await queryRunner.query(` CREATE TABLE face_search ( "faceId" uuid PRIMARY KEY REFERENCES asset_faces(id) ON DELETE CASCADE, embedding vector(512) NOT NULL )`); await queryRunner.query(`ALTER TABLE face_search ALTER COLUMN embedding SET STORAGE EXTERNAL`); - await queryRunner.query(`ALTER TABLE smart_search ADD COLUMN IF NOT EXISTS embedding vector(512)`); await queryRunner.query(`ALTER TABLE smart_search ALTER COLUMN embedding SET STORAGE EXTERNAL`); - const assetFacesColumns = await queryRunner.query( - `SELECT column_name as name - FROM information_schema.columns - WHERE table_name = 'asset_faces'`); - const hasFaceEmbeddings = assetFacesColumns.some((column: { name: string }) => column.name === 'embedding'); - if (hasFaceEmbeddings) { - await queryRunner.query(` - INSERT INTO face_search("faceId", embedding) - SELECT id, embedding - FROM asset_faces faces`); - } + await queryRunner.query(` + INSERT INTO face_search("faceId", embedding) + SELECT id, embedding + FROM asset_faces faces + WHERE faces.embedding IS NOT NULL`); await queryRunner.query(`ALTER TABLE asset_faces DROP COLUMN IF EXISTS embedding`);