Skip to content

Commit b9fb66c

Browse files
committed
use create table helper in kysely examples
1 parent caa670a commit b9fb66c

File tree

2 files changed

+3
-101
lines changed

2 files changed

+3
-101
lines changed
Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,3 @@
1-
import type { Kysely } from "kysely"
2-
import { sql } from "kysely"
1+
import { createQueueJobsTable } from "@vorsteh-queue/adapter-kysely"
32

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")
Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1 @@
1-
import type { Kysely } from "kysely"
2-
import { sql } from "kysely"
3-
4-
export async function up(db: Kysely<unknown>) {
5-
await db.schema
6-
.createTable("queue_jobs")
7-
.addColumn("id", "uuid", (col) => col.defaultTo(sql`gen_random_uuid()`).notNull())
8-
.addColumn("queue_name", "varchar(255)", (col) => col.notNull())
9-
.addColumn("name", "varchar(255)", (col) => col.notNull())
10-
.addColumn("payload", "jsonb", (col) => col.notNull())
11-
.addColumn("status", "varchar(50)", (col) => col.notNull())
12-
.addColumn("priority", "int4", (col) => col.notNull())
13-
.addColumn("attempts", "int4", (col) => col.defaultTo(0).notNull())
14-
.addColumn("max_attempts", "int4", (col) => col.notNull())
15-
.addColumn("timeout", "jsonb")
16-
.addColumn("cron", "varchar(255)")
17-
.addColumn("created_at", "timestamptz", (col) =>
18-
col.defaultTo(sql`timezone('utc'::text, now())`).notNull(),
19-
)
20-
.addColumn("process_at", "timestamptz", (col) => col.notNull())
21-
.addColumn("processed_at", "timestamptz")
22-
.addColumn("completed_at", "timestamptz")
23-
.addColumn("failed_at", "timestamptz")
24-
.addColumn("error", "jsonb")
25-
.addColumn("result", "jsonb")
26-
.addColumn("progress", "int4")
27-
.addColumn("repeat_every", "int4")
28-
.addColumn("repeat_limit", "int4")
29-
.addColumn("repeat_count", "int4")
30-
.execute()
31-
32-
await db.schema
33-
.createIndex("idx_queue_jobs_status_priority")
34-
.on("queue_jobs")
35-
36-
.columns(["queue_name", "status", "priority", "created_at"])
37-
.execute()
38-
39-
await db.schema
40-
.createIndex("idx_queue_jobs_process_at")
41-
.on("queue_jobs")
42-
43-
.column("process_at")
44-
.execute()
45-
}
46-
47-
export async function down(db: Kysely<unknown>) {
48-
await db.schema.dropTable("queue_jobs").execute()
49-
}
1+
export { down, up } from "@vorsteh-queue/adapter-kysely/migrations"

0 commit comments

Comments
 (0)