diff --git a/server/src/entities/exif.entity.ts b/server/src/entities/exif.entity.ts index 6f7aafadf4b9e..3461faa685035 100644 --- a/server/src/entities/exif.entity.ts +++ b/server/src/entities/exif.entity.ts @@ -98,20 +98,4 @@ export class ExifEntity { /* Video info */ @Column({ type: 'float8', nullable: true }) fps?: number | null; - - @Index('exif_text_searchable', { synchronize: false }) - @Column({ - type: 'tsvector', - generatedType: 'STORED', - select: false, - asExpression: `TO_TSVECTOR('english', - COALESCE(make, '') || ' ' || - COALESCE(model, '') || ' ' || - COALESCE(orientation, '') || ' ' || - COALESCE("lensModel", '') || ' ' || - COALESCE("city", '') || ' ' || - COALESCE("state", '') || ' ' || - COALESCE("country", ''))`, - }) - exifTextSearchableColumn!: string; } diff --git a/server/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts b/server/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts index 6bc1e562503ea..00a66d78e9ff4 100644 --- a/server/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts +++ b/server/src/migrations/1656889061566-MatchMigrationsWithTypeORMEntities.ts @@ -11,21 +11,6 @@ export class MatchMigrationsWithTypeORMEntities1656889061566 implements Migratio COALESCE("state", '') || ' ' || COALESCE("country", ''))) STORED`); await queryRunner.query(`ALTER TABLE "exif" ALTER COLUMN "exifTextSearchableColumn" SET NOT NULL`); - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'postgres', 'public', 'exif'], - ); - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, - [ - 'postgres', - 'public', - 'exif', - 'GENERATED_COLUMN', - 'exifTextSearchableColumn', - "TO_TSVECTOR('english',\n COALESCE(make, '') || ' ' ||\n COALESCE(model, '') || ' ' ||\n COALESCE(orientation, '') || ' ' ||\n COALESCE(\"lensModel\", '') || ' ' ||\n COALESCE(\"city\", '') || ' ' ||\n COALESCE(\"state\", '') || ' ' ||\n COALESCE(\"country\", ''))", - ], - ); await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "firstName" SET NOT NULL`); await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "lastName" SET NOT NULL`); await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "isAdmin" SET NOT NULL`); @@ -51,10 +36,6 @@ export class MatchMigrationsWithTypeORMEntities1656889061566 implements Migratio await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "isAdmin" DROP NOT NULL`); await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "lastName" DROP NOT NULL`); await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "firstName" DROP NOT NULL`); - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "exifTextSearchableColumn"`); await queryRunner.query(`ALTER TABLE "asset_album" DROP CONSTRAINT "FK_7ae4e03729895bf87e056d7b598"`); await queryRunner.query(`ALTER TABLE "asset_album" DROP CONSTRAINT "FK_256a30a03a4a0aff0394051397d"`); diff --git a/server/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts b/server/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts index 3dfc655fc6bc1..3b175be3e5c18 100644 --- a/server/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts +++ b/server/src/migrations/1658860470248-AddExifImageNameAsSearchableText.ts @@ -5,10 +5,6 @@ export class AddExifImageNameAsSearchableText1658860470248 implements MigrationI public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "exifTextSearchableColumn"`); - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); await queryRunner.query(`ALTER TABLE "exif" ADD "exifTextSearchableColumn" tsvector GENERATED ALWAYS AS (TO_TSVECTOR('english', COALESCE(make, '') || ' ' || COALESCE(model, '') || ' ' || @@ -18,33 +14,9 @@ export class AddExifImageNameAsSearchableText1658860470248 implements MigrationI COALESCE("city", '') || ' ' || COALESCE("state", '') || ' ' || COALESCE("country", ''))) STORED`); - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, - [ - 'immich', - 'public', - 'exif', - 'GENERATED_COLUMN', - 'exifTextSearchableColumn', - "TO_TSVECTOR('english',\n COALESCE(make, '') || ' ' ||\n COALESCE(model, '') || ' ' ||\n COALESCE(orientation, '') || ' ' ||\n COALESCE(\"lensModel\", '') || ' ' ||\n COALESCE(\"imageName\", '') || ' ' ||\n COALESCE(\"city\", '') || ' ' ||\n COALESCE(\"state\", '') || ' ' ||\n COALESCE(\"country\", ''))", - ], - ); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); - await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "exifTextSearchableColumn"`); - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, - ['immich', 'public', 'exif', 'GENERATED_COLUMN', 'exifTextSearchableColumn', ''], - ); await queryRunner.query(`ALTER TABLE "exif" ADD "exifTextSearchableColumn" tsvector NOT NULL`); } } diff --git a/server/src/migrations/1681159594469-RemoveImageNameFromEXIFTable.ts b/server/src/migrations/1681159594469-RemoveImageNameFromEXIFTable.ts index 87bf2a62e6736..e188ea35063e3 100644 --- a/server/src/migrations/1681159594469-RemoveImageNameFromEXIFTable.ts +++ b/server/src/migrations/1681159594469-RemoveImageNameFromEXIFTable.ts @@ -5,10 +5,6 @@ export class RemoveImageNameFromEXIFTable1681159594469 implements MigrationInter public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN IF EXISTS "exifTextSearchableColumn"`); - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); await queryRunner.query(`ALTER TABLE "exif" ADD "exifTextSearchableColumn" tsvector GENERATED ALWAYS AS (TO_TSVECTOR('english', COALESCE(make, '') || ' ' || COALESCE(model, '') || ' ' || @@ -17,37 +13,11 @@ export class RemoveImageNameFromEXIFTable1681159594469 implements MigrationInter COALESCE("city", '') || ' ' || COALESCE("state", '') || ' ' || COALESCE("country", ''))) STORED NOT NULL`); - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, - [ - 'immich', - 'public', - 'exif', - 'GENERATED_COLUMN', - 'exifTextSearchableColumn', - "TO_TSVECTOR('english',\n COALESCE(make, '') || ' ' ||\n COALESCE(model, '') || ' ' ||\n COALESCE(orientation, '') || ' ' ||\n COALESCE(\"lensModel\", '') || ' ' ||\n COALESCE(\"city\", '') || ' ' ||\n COALESCE(\"state\", '') || ' ' ||\n COALESCE(\"country\", ''))", - ], - ); await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "imageName"`); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, - ['GENERATED_COLUMN', 'exifTextSearchableColumn', 'immich', 'public', 'exif'], - ); await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "exifTextSearchableColumn"`); - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, - [ - 'immich', - 'public', - 'exif', - 'GENERATED_COLUMN', - 'exifTextSearchableColumn', - "TO_TSVECTOR('english',\n COALESCE(make, '') || ' ' ||\n COALESCE(model, '') || ' ' ||\n COALESCE(orientation, '') || ' ' ||\n COALESCE(\"lensModel\", '') || ' ' ||\n COALESCE(\"imageName\", '') || ' ' ||\n COALESCE(\"city\", '') || ' ' ||\n COALESCE(\"state\", '') || ' ' ||\n COALESCE(\"country\", ''))", - ], - ); await queryRunner.query(`ALTER TABLE "exif" ADD "exifTextSearchableColumn" tsvector GENERATED ALWAYS AS (TO_TSVECTOR('english', COALESCE(make, '') || ' ' || COALESCE(model, '') || ' ' || diff --git a/server/src/migrations/1700362016675-Geodata.ts b/server/src/migrations/1700362016675-Geodata.ts index 1ef562ff7effb..fa948e0896bb3 100644 --- a/server/src/migrations/1700362016675-Geodata.ts +++ b/server/src/migrations/1700362016675-Geodata.ts @@ -8,8 +8,6 @@ export class Geodata1700362016675 implements MigrationInterface { await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS earthdistance`) await queryRunner.query(`CREATE TABLE "geodata_admin2" ("key" character varying NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_1e3886455dbb684d6f6b4756726" PRIMARY KEY ("key"))`); await queryRunner.query(`CREATE TABLE "geodata_admin1" ("key" character varying NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_3fe3a89c5aac789d365871cb172" PRIMARY KEY ("key"))`); - await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, ["immich","public","geodata_places","GENERATED_COLUMN","admin1Key","\"countryCode\" || '.' || \"admin1Code\""]); - await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, ["immich","public","geodata_places","GENERATED_COLUMN","admin2Key","\"countryCode\" || '.' || \"admin1Code\" || '.' || \"admin2Code\""]); await queryRunner.query(`CREATE TABLE "geodata_places" ("id" integer NOT NULL, "name" character varying(200) NOT NULL, "longitude" double precision NOT NULL, "latitude" double precision NOT NULL, "countryCode" character(2) NOT NULL, "admin1Code" character varying(20), "admin2Code" character varying(80), "admin1Key" character varying GENERATED ALWAYS AS ("countryCode" || '.' || "admin1Code") STORED, "admin2Key" character varying GENERATED ALWAYS AS ("countryCode" || '.' || "admin1Code" || '.' || "admin2Code") STORED, "modificationDate" date NOT NULL, CONSTRAINT "PK_c29918988912ef4036f3d7fbff4" PRIMARY KEY ("id"))`); await queryRunner.query(`ALTER TABLE "geodata_places" ADD "earthCoord" earth GENERATED ALWAYS AS (ll_to_earth(latitude, longitude)) STORED`) await queryRunner.query(`CREATE INDEX "IDX_geodata_gist_earthcoord" ON "geodata_places" USING gist ("earthCoord");`) @@ -18,8 +16,6 @@ export class Geodata1700362016675 implements MigrationInterface { public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`DROP INDEX "IDX_geodata_gist_earthcoord"`); await queryRunner.query(`DROP TABLE "geodata_places"`); - await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, ["GENERATED_COLUMN","admin2Key","immich","public","geodata_places"]); - await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "database" = $3 AND "schema" = $4 AND "table" = $5`, ["GENERATED_COLUMN","admin1Key","immich","public","geodata_places"]); await queryRunner.query(`DROP TABLE "geodata_admin1"`); await queryRunner.query(`DROP TABLE "geodata_admin2"`); await queryRunner.query(`DROP EXTENSION cube`); diff --git a/server/src/migrations/1708059341865-GeodataLocationSearch.ts b/server/src/migrations/1708059341865-GeodataLocationSearch.ts index 136ca2598d60e..af2d5dc5f3530 100644 --- a/server/src/migrations/1708059341865-GeodataLocationSearch.ts +++ b/server/src/migrations/1708059341865-GeodataLocationSearch.ts @@ -49,30 +49,6 @@ export class GeodataLocationSearch1708059341865 implements MigrationInterface { CREATE INDEX idx_geodata_places_admin2_name ON geodata_places USING gin (f_unaccent("admin2Name") gin_trgm_ops)`); - - await queryRunner.query( - ` - DELETE FROM "typeorm_metadata" - WHERE - "type" = $1 AND - "name" = $2 AND - "database" = $3 AND - "schema" = $4 AND - "table" = $5`, - ['GENERATED_COLUMN', 'admin1Key', 'immich', 'public', 'geodata_places'], - ); - - await queryRunner.query( - ` - DELETE FROM "typeorm_metadata" - WHERE - "type" = $1 AND - "name" = $2 AND - "database" = $3 AND - "schema" = $4 AND - "table" = $5`, - ['GENERATED_COLUMN', 'admin2Key', 'immich', 'public', 'geodata_places'], - ); } public async down(queryRunner: QueryRunner): Promise { @@ -91,7 +67,7 @@ export class GeodataLocationSearch1708059341865 implements MigrationInterface { )`); await queryRunner.query(` - ALTER TABLE geodata_places + ALTER TABLE geodata_places ADD COLUMN "admin1Key" character varying GENERATED ALWAYS AS ("countryCode" || '.' || "admin1Code") STORED, ADD COLUMN "admin2Key" character varying @@ -128,25 +104,5 @@ export class GeodataLocationSearch1708059341865 implements MigrationInterface { SET "admin2Name" = admin2.name FROM geodata_admin2 admin2 WHERE admin2.key = "admin2Key";`); - - await queryRunner.query( - ` - INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") - VALUES ($1, $2, $3, $4, $5, $6)`, - ['immich', 'public', 'geodata_places', 'GENERATED_COLUMN', 'admin1Key', '"countryCode" || \'.\' || "admin1Code"'], - ); - - await queryRunner.query( - `INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") - VALUES ($1, $2, $3, $4, $5, $6)`, - [ - 'immich', - 'public', - 'geodata_places', - 'GENERATED_COLUMN', - 'admin2Key', - '"countryCode" || \'.\' || "admin1Code" || \'.\' || "admin2Code"', - ], - ); } } diff --git a/server/src/migrations/1715623169039-RemoveTextSearchColumn.ts b/server/src/migrations/1715623169039-RemoveTextSearchColumn.ts new file mode 100644 index 0000000000000..50e99f0b2a708 --- /dev/null +++ b/server/src/migrations/1715623169039-RemoveTextSearchColumn.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class RemoveTextSearchColumn1715623169039 implements MigrationInterface { + name = 'RemoveTextSearchColumn1715623169039' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "exif" DROP COLUMN "exifTextSearchableColumn"`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "exif" ADD "exifTextSearchableColumn" tsvector GENERATED ALWAYS AS (TO_TSVECTOR('english', + COALESCE(make, '') || ' ' || + COALESCE(model, '') || ' ' || + COALESCE(orientation, '') || ' ' || + COALESCE("lensModel", '') || ' ' || + COALESCE("city", '') || ' ' || + COALESCE("state", '') || ' ' || + COALESCE("country", ''))) STORED NOT NULL`); + } + +} diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index 0e5395c5bd17a..ae7df3655939e 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -70,10 +70,9 @@ export enum Orientation { Rotate270CW = '8', } -type ExifEntityWithoutGeocodeAndTypeOrm = Omit< - ExifEntity, - 'city' | 'state' | 'country' | 'description' | 'exifTextSearchableColumn' -> & { dateTimeOriginal: Date }; +type ExifEntityWithoutGeocodeAndTypeOrm = Omit & { + dateTimeOriginal: Date; +}; const exifDate = (dt: ExifDateTime | string | undefined) => (dt instanceof ExifDateTime ? dt?.toDate() : null); const tzOffset = (dt: ExifDateTime | string | undefined) => (dt instanceof ExifDateTime ? dt?.tzoffsetMinutes : null); diff --git a/server/test/fixtures/shared-link.stub.ts b/server/test/fixtures/shared-link.stub.ts index 94f39a69789e6..2ffbe1eb2b992 100644 --- a/server/test/fixtures/shared-link.stub.ts +++ b/server/test/fixtures/shared-link.stub.ts @@ -252,7 +252,6 @@ export const sharedLinkStub = { exposureTime: '1/16', fps: 100, asset: null as any, - exifTextSearchableColumn: '', profileDescription: 'sRGB', bitsPerSample: 8, colorspace: 'sRGB',