From 844f5a16a192676ca2d52a29f9c6032fb89e4bc0 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Mon, 13 May 2024 16:40:16 -0400 Subject: [PATCH] chore(server): remove unused column (#9431) * chore(server): remove unused column * fix: broken migrations --- server/src/entities/exif.entity.ts | 16 ------- ...1566-MatchMigrationsWithTypeORMEntities.ts | 19 -------- ...470248-AddExifImageNameAsSearchableText.ts | 28 ----------- ...1159594469-RemoveImageNameFromEXIFTable.ts | 30 ------------ .../src/migrations/1700362016675-Geodata.ts | 4 -- .../1708059341865-GeodataLocationSearch.ts | 46 +------------------ .../1715623169039-RemoveTextSearchColumn.ts | 21 +++++++++ server/src/services/metadata.service.ts | 7 ++- server/test/fixtures/shared-link.stub.ts | 1 - 9 files changed, 25 insertions(+), 147 deletions(-) create mode 100644 server/src/migrations/1715623169039-RemoveTextSearchColumn.ts diff --git a/server/src/entities/exif.entity.ts b/server/src/entities/exif.entity.ts index 6f7aafadf4..3461faa685 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 6bc1e56250..00a66d78e9 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 3dfc655fc6..3b175be3e5 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 87bf2a62e6..e188ea3506 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 1ef562ff7e..fa948e0896 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 136ca2598d..af2d5dc5f3 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 0000000000..50e99f0b2a --- /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 0e5395c5bd..ae7df36559 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 94f39a6978..2ffbe1eb2b 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',