refactor(ocr): remove obsolete OCR entity and migration files, and update asset job status and schema to accommodate new OCR table structure

This commit is contained in:
CoderKang 2025-06-02 20:41:18 +08:00 committed by mertalev
parent 3183a1ce05
commit 46ef02342d
No known key found for this signature in database
GPG key ID: DF6ABC77AAD98C95
9 changed files with 57 additions and 59 deletions

View file

@ -1,5 +0,0 @@
export class OcrEntity {
id!: string;
assetId!: string;
text!: string;
}

View file

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class UpsertOcrAssetJobStatus1743429240851 implements MigrationInterface {
name = 'UpsertOcrAssetJobStatus1743429240851';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE asset_job_status
ADD COLUMN IF NOT EXISTS "ocrAt" TIMESTAMP WITH TIME ZONE;
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE asset_job_status
DROP COLUMN IF EXISTS "ocrAt";
`);
}
}

View file

@ -1,22 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddOcrTable1743429592349 implements MigrationInterface {
name = 'AddOcrTable1743429592349';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS "asset_ocr"
(
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"assetId" uuid NOT NULL,
"text" text,
CONSTRAINT "PK_asset_ocr_id" PRIMARY KEY ("id")
);
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "asset_ocr" DROP CONSTRAINT "FK_asset_ocr_assetId"`);
await queryRunner.query(`DROP TABLE "asset_ocr"`);
}
}

View file

@ -35,6 +35,7 @@ import { AssetFileTable } from 'src/schema/tables/asset-file.table';
import { AssetJobStatusTable } from 'src/schema/tables/asset-job-status.table';
import { AssetMetadataAuditTable } from 'src/schema/tables/asset-metadata-audit.table';
import { AssetMetadataTable } from 'src/schema/tables/asset-metadata.table';
import { AssetOcrTable } from 'src/schema/tables/asset-ocr.table';
import { AssetTable } from 'src/schema/tables/asset.table';
import { AuditTable } from 'src/schema/tables/audit.table';
import { FaceSearchTable } from 'src/schema/tables/face-search.table';
@ -87,6 +88,7 @@ export class ImmichDatabase {
AssetMetadataTable,
AssetMetadataAuditTable,
AssetJobStatusTable,
AssetOcrTable,
AssetTable,
AssetFileTable,
AuditTable,

View file

@ -0,0 +1,9 @@
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await sql`ALTER TABLE "asset_job_status" ADD "ocrAt" timestamp with time zone;`.execute(db);
}
export async function down(db: Kysely<any>): Promise<void> {
await sql`ALTER TABLE "asset_job_status" DROP COLUMN "ocrAt";`.execute(db);
}

View file

@ -0,0 +1,13 @@
import { Kysely, sql } from 'kysely';
export async function up(db: Kysely<any>): Promise<void> {
await sql`CREATE TABLE "asset_ocr" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "assetId" uuid NOT NULL, "boundingBoxX1" integer NOT NULL DEFAULT 0, "boundingBoxY1" integer NOT NULL DEFAULT 0, "boundingBoxX2" integer NOT NULL DEFAULT 0, "boundingBoxY2" integer NOT NULL DEFAULT 0, "text" text NOT NULL);`.execute(db);
await sql`ALTER TABLE "asset_ocr" ADD CONSTRAINT "PK_5c37b36ceef9ac1f688b6c6bf22" PRIMARY KEY ("id");`.execute(db);
await sql`ALTER TABLE "asset_ocr" ADD CONSTRAINT "FK_dc592ec504976f5636e28bb84c6" FOREIGN KEY ("assetId") REFERENCES "assets" ("id") ON UPDATE CASCADE ON DELETE CASCADE;`.execute(db);
}
export async function down(db: Kysely<any>): Promise<void> {
await sql`ALTER TABLE "asset_ocr" DROP CONSTRAINT "PK_5c37b36ceef9ac1f688b6c6bf22";`.execute(db);
await sql`ALTER TABLE "asset_ocr" DROP CONSTRAINT "FK_dc592ec504976f5636e28bb84c6";`.execute(db);
await sql`DROP TABLE "asset_ocr";`.execute(db);
}

View file

@ -20,4 +20,7 @@ export class AssetJobStatusTable {
@Column({ type: 'timestamp with time zone', nullable: true })
thumbnailAt!: Timestamp | null;
@Column({ type: 'timestamp with time zone', nullable: true })
ocrAt!: Timestamp | null;
}

View file

@ -0,0 +1,30 @@
import { AssetTable } from 'src/schema/tables/asset.table';
import { Column, ForeignKeyColumn, PrimaryGeneratedColumn, Table } from 'src/sql-tools';
@Table('asset_ocr')
export class AssetOcrTable {
@PrimaryGeneratedColumn()
id!: string;
@ForeignKeyColumn(() => AssetTable, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
index: false,
})
assetId!: string;
@Column({ default: 0, type: 'integer' })
boundingBoxX1!: number;
@Column({ default: 0, type: 'integer' })
boundingBoxY1!: number;
@Column({ default: 0, type: 'integer' })
boundingBoxX2!: number;
@Column({ default: 0, type: 'integer' })
boundingBoxY2!: number;
@Column({ type: 'text' })
text!: string;
}

View file

@ -1,13 +0,0 @@
import { Column, CreateDateColumn, PrimaryGeneratedColumn, Table } from 'src/sql-tools';
@Table('asset_ocr')
export class AssetOcrTable {
@PrimaryGeneratedColumn()
id!: string;
@Column({ type: 'uuid' })
assetId!: string;
@CreateDateColumn()
text!: string;
}