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`);