|
1 | | -import type { Kysely } from "kysely" |
2 | | -import { sql } from "kysely" |
| 1 | +import { createQueueJobsTable } from "@vorsteh-queue/adapter-kysely" |
3 | 2 |
|
4 | | -export async function up(db: Kysely<unknown>) { |
5 | | - await db.schema.createSchema("custom_schema").ifNotExists().execute() |
6 | | - await db.schema |
7 | | - .withSchema("custom_schema") |
8 | | - .createTable("custom_queue_jobs") |
9 | | - .addColumn("id", "uuid", (col) => col.defaultTo(sql`gen_random_uuid()`).notNull()) |
10 | | - .addColumn("queue_name", "varchar(255)", (col) => col.notNull()) |
11 | | - .addColumn("name", "varchar(255)", (col) => col.notNull()) |
12 | | - .addColumn("payload", "jsonb", (col) => col.notNull()) |
13 | | - .addColumn("status", "varchar(50)", (col) => col.notNull()) |
14 | | - .addColumn("priority", "int4", (col) => col.notNull()) |
15 | | - .addColumn("attempts", "int4", (col) => col.defaultTo(0).notNull()) |
16 | | - .addColumn("max_attempts", "int4", (col) => col.notNull()) |
17 | | - .addColumn("timeout", "jsonb") |
18 | | - .addColumn("cron", "varchar(255)") |
19 | | - .addColumn("created_at", "timestamptz", (col) => |
20 | | - col.defaultTo(sql`timezone('utc'::text, now())`).notNull(), |
21 | | - ) |
22 | | - .addColumn("process_at", "timestamptz", (col) => col.notNull()) |
23 | | - .addColumn("processed_at", "timestamptz") |
24 | | - .addColumn("completed_at", "timestamptz") |
25 | | - .addColumn("failed_at", "timestamptz") |
26 | | - .addColumn("error", "jsonb") |
27 | | - .addColumn("result", "jsonb") |
28 | | - .addColumn("progress", "int4") |
29 | | - .addColumn("repeat_every", "int4") |
30 | | - .addColumn("repeat_limit", "int4") |
31 | | - .addColumn("repeat_count", "int4") |
32 | | - .execute() |
33 | | - |
34 | | - await db.schema |
35 | | - .createIndex("idx_custom_queue_jobs_status_priority") |
36 | | - .on("custom_queue_jobs") |
37 | | - |
38 | | - .columns(["queue_name", "status", "priority", "created_at"]) |
39 | | - .execute() |
40 | | - |
41 | | - await db.schema |
42 | | - .createIndex("idx_custom_queue_jobs_process_at") |
43 | | - .on("custom_queue_jobs") |
44 | | - |
45 | | - .column("process_at") |
46 | | - .execute() |
47 | | -} |
48 | | - |
49 | | -export async function down(db: Kysely<unknown>) { |
50 | | - // optional, in case you want to drop the custom schema as well |
51 | | - // await db.schema.dropSchema("custom_schema").execute() |
52 | | - await db.schema.dropTable("custom_queue_jobs").execute() |
53 | | -} |
| 3 | +export const { up, down } = createQueueJobsTable("custom_queue_jobs", "custom_schema") |
0 commit comments