mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
simplify
This commit is contained in:
parent
90709b4788
commit
8322af0baf
@ -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`);
|
||||
}
|
||||
FROM asset_faces faces
|
||||
WHERE faces.embedding IS NOT NULL`);
|
||||
|
||||
await queryRunner.query(`ALTER TABLE asset_faces DROP COLUMN IF EXISTS embedding`);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user