From b05848f5ab156a0baaae5e93221ad63f467f433e Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 14 Feb 2026 01:13:13 -0500 Subject: [PATCH] tetris --- ....ts => 1771049539032-AddJobQueueTables.ts} | 180 +++++++++--------- server/src/schema/tables/job.table.ts | 40 ++-- 2 files changed, 110 insertions(+), 110 deletions(-) rename server/src/schema/migrations/{1771043785018-AddJobQueueTables.ts => 1771049539032-AddJobQueueTables.ts} (100%) diff --git a/server/src/schema/migrations/1771043785018-AddJobQueueTables.ts b/server/src/schema/migrations/1771049539032-AddJobQueueTables.ts similarity index 100% rename from server/src/schema/migrations/1771043785018-AddJobQueueTables.ts rename to server/src/schema/migrations/1771049539032-AddJobQueueTables.ts index 92fbb7c08d..72fc5cff78 100644 --- a/server/src/schema/migrations/1771043785018-AddJobQueueTables.ts +++ b/server/src/schema/migrations/1771049539032-AddJobQueueTables.ts @@ -3,14 +3,14 @@ import { Kysely, sql } from 'kysely'; export async function up(db: Kysely): Promise { await sql`CREATE TABLE "jobs_thumbnail_generation" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_thumbnail_generation_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -18,14 +18,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_thumbnail_generation_pending" ON "jobs_thumbnail_generation" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_metadata_extraction" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_metadata_extraction_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -33,14 +33,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_metadata_extraction_pending" ON "jobs_metadata_extraction" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_video_conversion" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_video_conversion_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -48,14 +48,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_video_conversion_pending" ON "jobs_video_conversion" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_face_detection" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_face_detection_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -63,14 +63,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_face_detection_pending" ON "jobs_face_detection" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_facial_recognition" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_facial_recognition_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -78,14 +78,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_facial_recognition_pending" ON "jobs_facial_recognition" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_smart_search" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_smart_search_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -93,14 +93,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_smart_search_pending" ON "jobs_smart_search" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_duplicate_detection" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_duplicate_detection_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -108,14 +108,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_duplicate_detection_pending" ON "jobs_duplicate_detection" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_background_task" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_background_task_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -123,14 +123,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_background_task_pending" ON "jobs_background_task" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_storage_template_migration" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_storage_template_migration_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -138,14 +138,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_storage_template_migration_pending" ON "jobs_storage_template_migration" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_migration" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_migration_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -153,14 +153,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_migration_pending" ON "jobs_migration" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_search" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_search_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -168,14 +168,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_search_pending" ON "jobs_search" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_sidecar" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_sidecar_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -183,14 +183,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_sidecar_pending" ON "jobs_sidecar" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_library" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_library_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -198,14 +198,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_library_pending" ON "jobs_library" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_notification" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_notification_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -213,14 +213,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_notification_pending" ON "jobs_notification" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_backup_database" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_backup_database_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -228,14 +228,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_backup_database_pending" ON "jobs_backup_database" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_ocr" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_ocr_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -243,14 +243,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_ocr_pending" ON "jobs_ocr" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_workflow" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_workflow_pkey" PRIMARY KEY ("id") );`.execute(db); @@ -258,14 +258,14 @@ export async function up(db: Kysely): Promise { await sql`CREATE INDEX "IDX_jobs_workflow_pending" ON "jobs_workflow" ("priority", "id") WHERE status = 0;`.execute(db); await sql`CREATE TABLE "jobs_editor" ( "id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, - "code" smallint NOT NULL, - "data" jsonb, - "priority" smallint NOT NULL DEFAULT 0, - "status" smallint NOT NULL DEFAULT 0, - "dedupKey" text, "runAfter" timestamp with time zone NOT NULL DEFAULT now(), "startedAt" timestamp with time zone, "expiresAt" timestamp with time zone, + "code" smallint NOT NULL, + "priority" smallint NOT NULL DEFAULT 0, + "status" smallint NOT NULL DEFAULT 0, + "data" jsonb, + "dedupKey" text, "error" text, CONSTRAINT "jobs_editor_pkey" PRIMARY KEY ("id") );`.execute(db); diff --git a/server/src/schema/tables/job.table.ts b/server/src/schema/tables/job.table.ts index a4142b1e5a..37eae6ff41 100644 --- a/server/src/schema/tables/job.table.ts +++ b/server/src/schema/tables/job.table.ts @@ -3,14 +3,14 @@ import { Column, ConfigurationParameter, Generated, Index, PrimaryColumn, Table export type JobTable = { id: Generated; - code: JobCode; - data: unknown; - priority: Generated; - status: Generated; - dedupKey: string | null; runAfter: Generated; startedAt: Date | null; expiresAt: Date | null; + code: JobCode; + priority: Generated; + status: Generated; + data: unknown; + dedupKey: string | null; error: string | null; }; @@ -19,21 +19,6 @@ function defineJobTable(name: string) { @PrimaryColumn({ type: 'bigint', identity: true }) id!: Generated; - @Column({ type: 'smallint' }) - code!: JobCode; - - @Column({ type: 'jsonb', nullable: true }) - data!: unknown; - - @Column({ type: 'smallint', default: 0 }) - priority!: Generated; - - @Column({ type: 'smallint', default: 0 }) - status!: Generated; - - @Column({ type: 'text', nullable: true }) - dedupKey!: string | null; - @Column({ type: 'timestamp with time zone', default: () => 'now()' }) runAfter!: Generated; @@ -43,6 +28,21 @@ function defineJobTable(name: string) { @Column({ type: 'timestamp with time zone', nullable: true }) expiresAt!: Date | null; + @Column({ type: 'smallint' }) + code!: JobCode; + + @Column({ type: 'smallint', default: 0 }) + priority!: Generated; + + @Column({ type: 'smallint', default: 0 }) + status!: Generated; + + @Column({ type: 'jsonb', nullable: true }) + data!: unknown; + + @Column({ type: 'text', nullable: true }) + dedupKey!: string | null; + @Column({ type: 'text', nullable: true }) error!: string | null; }