diff --git a/server/src/infra/entities/asset-face.entity.ts b/server/src/infra/entities/asset-face.entity.ts index 363e3838e..4e9f83370 100644 --- a/server/src/infra/entities/asset-face.entity.ts +++ b/server/src/infra/entities/asset-face.entity.ts @@ -2,7 +2,7 @@ import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn } from 'typeor import { AssetEntity } from './asset.entity'; import { PersonEntity } from './person.entity'; -@Entity('asset_faces') +@Entity('asset_faces', { synchronize: false }) @Index(['personId', 'assetId']) export class AssetFaceEntity { @PrimaryGeneratedColumn('uuid') @@ -14,6 +14,7 @@ export class AssetFaceEntity { @Column({ nullable: true, type: 'uuid' }) personId!: string | null; + @Index('face_index', { synchronize: false }) @Column({ type: 'float4', array: true, select: false }) embedding!: number[]; diff --git a/server/src/infra/entities/exif.entity.ts b/server/src/infra/entities/exif.entity.ts index d1d6ca842..7b465c3c5 100644 --- a/server/src/infra/entities/exif.entity.ts +++ b/server/src/infra/entities/exif.entity.ts @@ -46,6 +46,7 @@ export class ExifEntity { @Column({ type: 'varchar', nullable: true }) projectionType!: string | null; + @Index('exif_city') @Column({ type: 'varchar', nullable: true }) city!: string | null; diff --git a/server/src/infra/entities/smart-info.entity.ts b/server/src/infra/entities/smart-info.entity.ts index ae3edd840..2606de60e 100644 --- a/server/src/infra/entities/smart-info.entity.ts +++ b/server/src/infra/entities/smart-info.entity.ts @@ -1,7 +1,7 @@ import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm'; import { AssetEntity } from './asset.entity'; -@Entity('smart_info') +@Entity('smart_info', { synchronize: false }) export class SmartInfoEntity { @OneToOne(() => AssetEntity, { onDelete: 'CASCADE', nullable: true }) @JoinColumn({ name: 'assetId', referencedColumnName: 'id' }) diff --git a/server/src/infra/entities/smart-search.entity.ts b/server/src/infra/entities/smart-search.entity.ts index 7c8e9ca43..2b295ac90 100644 --- a/server/src/infra/entities/smart-search.entity.ts +++ b/server/src/infra/entities/smart-search.entity.ts @@ -1,7 +1,7 @@ -import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm'; +import { Column, Entity, Index, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm'; import { AssetEntity } from './asset.entity'; -@Entity('smart_search') +@Entity('smart_search', { synchronize: false }) export class SmartSearchEntity { @OneToOne(() => AssetEntity, { onDelete: 'CASCADE', nullable: true }) @JoinColumn({ name: 'assetId', referencedColumnName: 'id' }) @@ -10,6 +10,7 @@ export class SmartSearchEntity { @PrimaryColumn() assetId!: string; + @Index('clip_index', { synchronize: false }) @Column({ type: 'float4', array: true, diff --git a/server/src/infra/migrations/1700713871511-UsePgVectors.ts b/server/src/infra/migrations/1700713871511-UsePgVectors.ts index bf0d45361..98e5082e3 100644 --- a/server/src/infra/migrations/1700713871511-UsePgVectors.ts +++ b/server/src/infra/migrations/1700713871511-UsePgVectors.ts @@ -34,7 +34,9 @@ export class UsePgVectors1700713871511 implements MigrationInterface { SELECT si."assetId", si."clipEmbedding" FROM smart_info si WHERE "clipEmbedding" IS NOT NULL`); - } + + await queryRunner.query(`ALTER TABLE smart_info DROP COLUMN IF EXISTS "clipEmbedding"`); + } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE asset_faces ALTER COLUMN embedding TYPE real array`); diff --git a/server/src/infra/migrations/1700713994428-AddCLIPEmbeddingIndex.ts b/server/src/infra/migrations/1700713994428-AddCLIPEmbeddingIndex.ts index 0854bb0e1..7a1a1144d 100644 --- a/server/src/infra/migrations/1700713994428-AddCLIPEmbeddingIndex.ts +++ b/server/src/infra/migrations/1700713994428-AddCLIPEmbeddingIndex.ts @@ -5,12 +5,12 @@ export class AddCLIPEmbeddingIndex1700713994428 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` - CREATE INDEX IF NOT EXISTS clip_index ON smart_search - USING vectors (embedding cosine_ops) WITH (options = $$ - [indexing.hnsw] - m = 16 - ef_construction = 300 - $$);`); + CREATE INDEX IF NOT EXISTS clip_index ON smart_search + USING vectors (embedding cosine_ops) WITH (options = $$ + [indexing.hnsw] + m = 16 + ef_construction = 300 + $$);`); } public async down(queryRunner: QueryRunner): Promise { diff --git a/server/src/infra/migrations/1700714033632-AddFaceEmbeddingIndex.ts b/server/src/infra/migrations/1700714033632-AddFaceEmbeddingIndex.ts index 669d24536..0ac7b0cd4 100644 --- a/server/src/infra/migrations/1700714033632-AddFaceEmbeddingIndex.ts +++ b/server/src/infra/migrations/1700714033632-AddFaceEmbeddingIndex.ts @@ -5,12 +5,12 @@ export class AddFaceEmbeddingIndex1700714033632 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(` - CREATE INDEX IF NOT EXISTS face_index ON asset_faces - USING vectors (embedding cosine_ops) WITH (options = $$ - [indexing.hnsw] - m = 16 - ef_construction = 300 - $$);`); + CREATE INDEX IF NOT EXISTS face_index ON asset_faces + USING vectors (embedding cosine_ops) WITH (options = $$ + [indexing.hnsw] + m = 16 + ef_construction = 300 + $$);`); } public async down(queryRunner: QueryRunner): Promise { diff --git a/server/src/infra/migrations/1700714105178-AddExifCityIndex.ts b/server/src/infra/migrations/1700714105178-AddExifCityIndex.ts deleted file mode 100644 index 1c4a660f6..000000000 --- a/server/src/infra/migrations/1700714105178-AddExifCityIndex.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class AddExifCityIndex1700714105178 implements MigrationInterface { - name = 'AddExifCityIndex1700714105178'; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE INDEX IF NOT EXISTS exif_city ON exif (city);`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP INDEX IF EXISTS exif_city;`); - } -} diff --git a/server/src/infra/migrations/1701665867595-AddExifCityIndex.ts b/server/src/infra/migrations/1701665867595-AddExifCityIndex.ts new file mode 100644 index 000000000..9979762dc --- /dev/null +++ b/server/src/infra/migrations/1701665867595-AddExifCityIndex.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddExifCityIndex1701665867595 implements MigrationInterface { + name = 'AddExifCityIndex1701665867595' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "exif_city" ON "exif" ("city") `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."exif_city"`); + } + +}