mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
simplify
This commit is contained in:
parent
90709b4788
commit
8322af0baf
1 changed files with 8 additions and 12 deletions
|
@ -9,26 +9,22 @@ export class AddFaceSearchRelation1718486162779 implements MigrationInterface {
|
||||||
await queryRunner.query(`SET vectors.pgvector_compatibility=on`);
|
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(`
|
await queryRunner.query(`
|
||||||
CREATE TABLE face_search (
|
CREATE TABLE face_search (
|
||||||
"faceId" uuid PRIMARY KEY REFERENCES asset_faces(id) ON DELETE CASCADE,
|
"faceId" uuid PRIMARY KEY REFERENCES asset_faces(id) ON DELETE CASCADE,
|
||||||
embedding vector(512) NOT NULL )`);
|
embedding vector(512) NOT NULL )`);
|
||||||
|
|
||||||
await queryRunner.query(`ALTER TABLE face_search ALTER COLUMN embedding SET STORAGE EXTERNAL`);
|
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`);
|
await queryRunner.query(`ALTER TABLE smart_search ALTER COLUMN embedding SET STORAGE EXTERNAL`);
|
||||||
|
|
||||||
const assetFacesColumns = await queryRunner.query(
|
await queryRunner.query(`
|
||||||
`SELECT column_name as name
|
INSERT INTO face_search("faceId", embedding)
|
||||||
FROM information_schema.columns
|
SELECT id, embedding
|
||||||
WHERE table_name = 'asset_faces'`);
|
FROM asset_faces faces
|
||||||
const hasFaceEmbeddings = assetFacesColumns.some((column: { name: string }) => column.name === 'embedding');
|
WHERE faces.embedding IS NOT NULL`);
|
||||||
if (hasFaceEmbeddings) {
|
|
||||||
await queryRunner.query(`
|
|
||||||
INSERT INTO face_search("faceId", embedding)
|
|
||||||
SELECT id, embedding
|
|
||||||
FROM asset_faces faces`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await queryRunner.query(`ALTER TABLE asset_faces DROP COLUMN IF EXISTS embedding`);
|
await queryRunner.query(`ALTER TABLE asset_faces DROP COLUMN IF EXISTS embedding`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue