feat: Add BatchJob entity (#1324)
* added entity * better typing * make requested changes * add migration
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
|
||||||
|
export class addBatchJobModel1649775522087 implements MigrationInterface {
|
||||||
|
name = "addBatchJobModel1649775522087"
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TYPE "batch_job_status_enum" AS ENUM('created', 'processing', 'awaiting_confirmation', 'completed')`
|
||||||
|
)
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "batch_job" ("id" character varying NOT NULL, "type" text NOT NULL, "status" "public"."batch_job_status_enum" NOT NULL, "created_by" text, "context" jsonb, "result" jsonb, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, CONSTRAINT "PK_e57f84d485145d5be96bc6d871e" PRIMARY KEY ("id"))`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP TABLE "batch_job"`)
|
||||||
|
await queryRunner.query(`DROP TYPE "batch_job_status_enum"`)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import {
|
||||||
|
BeforeInsert,
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
|
Entity,
|
||||||
|
PrimaryColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
} from "typeorm"
|
||||||
|
import { ulid } from "ulid"
|
||||||
|
import { BatchJobStatus } from "../types/batch-job"
|
||||||
|
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class BatchJob {
|
||||||
|
@PrimaryColumn()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@DbAwareColumn({ type: "text" })
|
||||||
|
type: string
|
||||||
|
|
||||||
|
@DbAwareColumn({ type: "enum", enum: BatchJobStatus })
|
||||||
|
status: BatchJobStatus
|
||||||
|
|
||||||
|
@Column({ type: "text", nullable: true })
|
||||||
|
created_by: string | null
|
||||||
|
|
||||||
|
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||||
|
context: Record<string, unknown>
|
||||||
|
|
||||||
|
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||||
|
result: Record<string, unknown>
|
||||||
|
|
||||||
|
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||||
|
created_at: Date
|
||||||
|
|
||||||
|
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||||
|
updated_at: Date
|
||||||
|
|
||||||
|
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||||
|
deleted_at: Date | null
|
||||||
|
|
||||||
|
@BeforeInsert()
|
||||||
|
private beforeInsert() {
|
||||||
|
if (this.id) return
|
||||||
|
const id = ulid()
|
||||||
|
this.id = `batch_${id}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema batch_job
|
||||||
|
* title: "Batch Job"
|
||||||
|
* description: "A Batch Job."
|
||||||
|
* x-resourceId: batch_job
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* description: "The unique identifier for the batch job."
|
||||||
|
* type: string
|
||||||
|
* type:
|
||||||
|
* description: "The type of batch job."
|
||||||
|
* type: string
|
||||||
|
* enum:
|
||||||
|
* - product_import
|
||||||
|
* - product_export
|
||||||
|
* status:
|
||||||
|
* description: "The status of the batch job."
|
||||||
|
* type: string
|
||||||
|
* enum:
|
||||||
|
* - created
|
||||||
|
* - processing
|
||||||
|
* - awaiting_confirmation
|
||||||
|
* - completed
|
||||||
|
* created_by:
|
||||||
|
* description: "The unique identifier of the user that created the batch job."
|
||||||
|
* type: string
|
||||||
|
* context:
|
||||||
|
* description: "The context of the batch job, the type of the batch job determines what the context should contain."
|
||||||
|
* type: object
|
||||||
|
* result:
|
||||||
|
* description: "The result of the batch job."
|
||||||
|
* type: object
|
||||||
|
* created_at:
|
||||||
|
* description: "The date with timezone at which the resource was created."
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* updated_at:
|
||||||
|
* description: "The date with timezone at which the resource was last updated."
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
* deleted_at:
|
||||||
|
* description: "The date with timezone at which the resource was deleted."
|
||||||
|
* type: string
|
||||||
|
* format: date-time
|
||||||
|
*/
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export enum BatchJobStatus {
|
||||||
|
CREATED = "created",
|
||||||
|
PROCESSING = "processing",
|
||||||
|
AWAITING_CONFIRMATION = "awaiting_confirmation",
|
||||||
|
COMPLETED = "completed",
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user