1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00
This commit is contained in:
mertalev 2024-07-03 19:54:08 -04:00
parent 90709b4788
commit 8322af0baf
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3

View file

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