Skip to content

Commit 92c0032

Browse files
authored
Merge pull request #40 from noxify/custom-schema-table-name
Custom schema & table name
2 parents e94e5a4 + b03d5b4 commit 92c0032

File tree

81 files changed

+3153
-1461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3153
-1461
lines changed

.changeset/crazy-colts-march.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
"@vorsteh-queue/adapter-drizzle": minor
3+
"@vorsteh-queue/adapter-kysely": minor
4+
"@vorsteh-queue/adapter-prisma": minor
5+
"@vorsteh-queue/core": minor
6+
---
7+
8+
## Dynamic Schema & Table Names
9+
10+
- All adapters (Drizzle, Kysely, Prisma) now support configurable schema and table names for queue jobs.
11+
- Enables an easier integration in existing DB setups.
12+
13+
## Example: Drizzle Adapter with Custom Schema & Table
14+
15+
```typescript
16+
// drizzle-schema.ts
17+
import { createQueueJobsTable } from "@vorsteh-queue/adapter-drizzle"
18+
19+
export const { table: customQueueJobs, schema: customSchema } = createQueueJobsTable(
20+
"custom_queue_jobs",
21+
"custom_schema",
22+
)
23+
24+
// queue.ts
25+
import { drizzle } from "drizzle-orm/node-postgres"
26+
import { Pool } from "pg"
27+
import * as schema from "src/drizzle-schema.ts2
28+
29+
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-drizzle"
30+
31+
const pool = new Pool({ connectionString: process.env.DATABASE_URL })
32+
const db = drizzle(pool, { schema })
33+
34+
const adapter = new PostgresQueueAdapter(db, {
35+
modelName: "customQueueJobs",
36+
})
37+
38+
// The queue will now use the specified schema and table
39+
const queue = new Queue(adapter, { name: "my-queue" })
40+
```

.changeset/upset-symbols-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-vorsteh-queue": patch
3+
---
4+
5+
update deps

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ubuntu-latest
3434
strategy:
3535
matrix:
36-
node-version: [20, 22]
36+
node-version: [20, 22, 24]
3737
name: Test (Node.js ${{ matrix.node-version }})
3838
steps:
3939
- uses: actions/checkout@v4
@@ -67,7 +67,7 @@ jobs:
6767

6868
- name: Test Prisma
6969
run: |
70-
pnpm -F adapter-prisma prisma:generate
70+
pnpm -F adapter-prisma prisma:generate_test
7171
pnpm test:prisma
7272
env:
7373
# Ensure Docker is available for Testcontainers
@@ -136,7 +136,7 @@ jobs:
136136
137137
- name: Test PostgreSQL (Postgres ${{ matrix.pg-version }})
138138
run: |
139-
pnpm -F adapter-prisma prisma:generate
139+
pnpm -F adapter-prisma prisma:generate_test
140140
pnpm test:prisma
141141
env:
142142
# Ensure Docker is available for Testcontainers

apps/docs/content/docs/02.packages/adapter-drizzle.mdx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const queue = new Queue(adapter)
2727

2828
## Supported providers
2929

30-
- PGlite
31-
- Postgres.JS
32-
- Node Progress
30+
- PGlite - https://orm.drizzle.team/docs/connect-pglite
31+
- Postgres.JS - https://orm.drizzle.team/docs/get-started-postgresql#postgresjs
32+
- Node Progress - https://orm.drizzle.team/docs/get-started-postgresql#node-postgres
3333

3434
## Database Setup
3535

@@ -53,6 +53,35 @@ If you don't want to use the pre-defined schema, you can create your own schema
5353
path="queue-jobs.ts"
5454
/>
5555

56+
### Custom Table & Schema Names
57+
58+
To create a table with custom name and schema, you can use the `createQueueJobsTable` helper, which will create the table without taking care about the field definitions:
59+
60+
```typescript path="drizzle-schema.ts"
61+
import { createQueueJobsTable } from "@vorsteh-queue/adapter-drizzle"
62+
63+
export const { table: customQueueJobs, schema: customSchema } = createQueueJobsTable(
64+
"custom_queue_jobs", // your custom table name
65+
"custom_schema", // your custom schema name
66+
)
67+
```
68+
69+
To use the custom table and schema in the adapter, pass the adapter configuration to the `PostgresQueueAdapter`:
70+
71+
```typescript
72+
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-drizzle"
73+
74+
const adapter = new PostgresQueueAdapter(db, {
75+
// Your custom model name ( based on the example above - `table: customQueueJobs`)
76+
modelName: "customQueueJobs",
77+
})
78+
```
79+
80+
<Note title="Want to see it in action?">
81+
Checkout our drizzle example with [custom schema and
82+
table](/docs/examples/drizzle-custom-schema-table/).
83+
</Note>
84+
5685
### Migration
5786

5887
To run the migrations, we recommend to use [`drizzle-kit`](https://orm.drizzle.team/docs/kit-overview).

apps/docs/content/docs/02.packages/adapter-kysely.mdx

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,18 @@ const queue = new Queue(adapter)
4646

4747
## Supported providers
4848

49-
- PGlite
50-
- Postgres.JS
51-
- Node Progress
49+
- PGlite - https://github.com/czeidler/kysely-pglite-dialect
50+
- Postgres.JS - https://github.com/kysely-org/kysely-postgres-js
51+
- Node Progress - https://kysely-org.github.io/kysely-apidoc/classes/PostgresDialect.html
5252

5353
## Database Setup
5454

5555
### Schema
5656

5757
The adapter includes a pre-defined migration:
5858

59-
```typescript
60-
// migrations/queue-jobs.ts
61-
import { down, up } from "@vorsteh-queue/adapter-kysely/migrations"
62-
63-
// Use in your schema file
64-
export { up, down }
59+
```typescript path="migrations/queue-jobs.ts"
60+
export { down, up } from "@vorsteh-queue/adapter-kysely/migrations"
6561
```
6662

6763
If you don't want to use the pre-defined schema, you can create your own migration.
@@ -70,9 +66,53 @@ If you don't want to use the pre-defined schema, you can create your own migrati
7066
source="./packages/adapter-kysely/src/migrations/queue_table.ts"
7167
language="ts"
7268
showToolbar={true}
73-
path="queue-jobs.ts"
69+
path="/migrations/queue-jobs.ts"
7470
/>
7571

72+
### Custom Table & Schema Names
73+
74+
To create a table with custom name and schema, you can use the `createQueueJobsTable` helper, which will create the table without taking care about the field definitions:
75+
76+
```typescript path="migrations/queue-jobs.ts"
77+
import { createQueueJobsTable } from "@vorsteh-queue/adapter-kysely"
78+
79+
export const { up, down } = createQueueJobsTable(
80+
// your custom table name
81+
"custom_queue_jobs",
82+
// your custom schema name
83+
"custom_schema",
84+
)
85+
```
86+
87+
To use the custom table and schema in the adapter, pass the adapter configuration to the `PostgresQueueAdapter`:
88+
89+
```typescript
90+
import { Kysely } from "kysely"
91+
92+
import type { QueueJobTableDefinition } from "@vorsteh-queue/adapter-kysely/types"
93+
import { PostgresQueueAdapter } from "@vorsteh-queue/adapter-kysely"
94+
95+
interface DB {
96+
custom_queue_jobs: QueueJobTableDefinition
97+
}
98+
99+
const db = new Kysely<DB>({
100+
//... your Kysely configuration
101+
})
102+
103+
const adapter = new PostgresQueueAdapter(db, {
104+
// Your custom schema name
105+
schemaName: "custom_schema",
106+
// Your custom table name
107+
tableName: "custom_queue_jobs",
108+
})
109+
```
110+
111+
<Note title="Want to see it in action?">
112+
Checkout our kysely example with [custom schema and
113+
table](/docs/examples/kysely-custom-schema-table/).
114+
</Note>
115+
76116
### Migration
77117

78118
To run the migrations, we recommend to use [`kysely-ctl`](https://github.com/kysely-org/kysely-ctl).

apps/docs/content/docs/02.packages/adapter-prisma.mdx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The Prisma adapter provides PostgreSQL support using Prisma ORM, offering genera
1212

1313
## Quick Start
1414

15+
### With prisma-client-js
16+
1517
```typescript
1618
import { PrismaClient } from "@prisma/client"
1719

@@ -23,6 +25,21 @@ const adapter = new PostgresPrismaQueueAdapter(prisma)
2325
const queue = new Queue(adapter)
2426
```
2527

28+
### With prisma-client
29+
30+
```typescript
31+
import { PrismaPg } from "@prisma/adapter-pg"
32+
import { PrismaClient } from "src/generated/prisma/client"
33+
34+
import { PostgresPrismaQueueAdapter } from "@vorsteh-queue/adapter-prisma"
35+
import { Queue } from "@vorsteh-queue/core"
36+
37+
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
38+
const prisma = new PrismaClient({ adapter })
39+
const adapter = new PostgresPrismaQueueAdapter(prisma)
40+
const queue = new Queue(adapter)
41+
```
42+
2643
## Database Setup
2744

2845
### Schema
@@ -37,6 +54,49 @@ Add the queue job model to your `schema.prisma`:
3754
focusedLines="17-43"
3855
/>
3956

57+
### Custom Table & Schema Names
58+
59+
To use the custom table and schema with prisma, you have to customize the prisma schema.
60+
Here an example with custom schema and table name ( the relevant parts are highlighted ):
61+
62+
<RemoteCodeBlock
63+
source="./examples/prisma-custom-schema-table/prisma/schema.prisma"
64+
language="prisma"
65+
showToolbar={true}
66+
showLineNumbers={true}
67+
path="prisma/schema.prisma"
68+
focusedLines="16,19,44-45"
69+
/>
70+
71+
To use the custom table and schema in the adapter, pass the adapter configuration to the `PostgresQueueAdapter`:
72+
73+
```typescript
74+
import { PrismaPg } from "@prisma/adapter-pg"
75+
import { PrismaClient } from "src/generated/prisma/client"
76+
77+
import { PostgresPrismaQueueAdapter } from "@vorsteh-queue/adapter-prisma"
78+
import { Queue } from "@vorsteh-queue/core"
79+
80+
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
81+
const prisma = new PrismaClient({ adapter })
82+
83+
const adapter = new PostgresQueueAdapter(prisma, {
84+
// Your custom model name ( based on the example above )
85+
modelName: "CustomQueueJobs",
86+
// Your custom schema name
87+
schemaName: "custom_schema",
88+
// Your custom table name
89+
tableName: "custom_queue_jobs",
90+
})
91+
92+
const queue = new Queue(adapter)
93+
```
94+
95+
<Note title="Want to see it in action?">
96+
Checkout our prisma example with [custom schema and
97+
table](/docs/examples/prisma-custom-schema-table/).
98+
</Note>
99+
40100
### Migration
41101

42102
To run the migrations, we recommend to use the [`prisma cli`](https://www.prisma.io/docs/orm/tools/prisma-cli).

apps/docs/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
"@mdx-js/loader": "3.1.1",
2424
"@mdx-js/node-loader": "3.1.1",
2525
"@mdx-js/react": "3.1.1",
26-
"@next/mdx": "16.0.0",
26+
"@next/mdx": "16.0.1",
2727
"@radix-ui/react-collapsible": "^1.1.12",
2828
"@radix-ui/react-compose-refs": "1.1.2",
2929
"@radix-ui/react-dialog": "^1.1.15",
3030
"@radix-ui/react-dropdown-menu": "2.1.16",
3131
"@radix-ui/react-id": "1.1.1",
32-
"@radix-ui/react-primitive": "2.1.3",
33-
"@radix-ui/react-separator": "^1.1.7",
34-
"@radix-ui/react-slot": "^1.2.3",
32+
"@radix-ui/react-primitive": "2.1.4",
33+
"@radix-ui/react-separator": "^1.1.8",
34+
"@radix-ui/react-slot": "^1.2.4",
3535
"@radix-ui/react-tabs": "1.1.13",
3636
"@radix-ui/react-tooltip": "^1.2.8",
3737
"@vercel/og": "0.8.5",
@@ -40,9 +40,9 @@
4040
"date-fns": "^4.1.0",
4141
"globby": "15.0.0",
4242
"interweave": "13.1.1",
43-
"lucide-react": "0.548.0",
43+
"lucide-react": "0.552.0",
4444
"multimatch": "7.0.0",
45-
"next": "16.0.0",
45+
"next": "16.0.1",
4646
"next-themes": "latest",
4747
"p-map": "7.0.3",
4848
"react": "19.2.0",
@@ -54,8 +54,8 @@
5454
"remark-mdx-frontmatter": "5.2.0",
5555
"remark-squeeze-paragraphs": "6.0.0",
5656
"remark-strip-badges": "7.0.0",
57-
"renoun": "10.7.0",
58-
"tm-grammars": "1.25.1",
57+
"renoun": "10.9.0",
58+
"tm-grammars": "1.25.3",
5959
"tm-themes": "1.10.12",
6060
"ts-morph": "27.0.2",
6161
"tw-animate-css": "^1.4.0",
@@ -66,7 +66,7 @@
6666
"@tailwindcss/postcss": "4.1.16",
6767
"@tailwindcss/typography": "0.5.19",
6868
"@types/mdx": "2.0.13",
69-
"@types/node": "22.18.12",
69+
"@types/node": "22.19.0",
7070
"@types/react": "19.2.2",
7171
"@types/react-dom": "19.2.2",
7272
"@types/serve-handler": "6.1.4",
@@ -77,7 +77,7 @@
7777
"@vorsteh-queue/eslint-config": "workspace:*",
7878
"@vorsteh-queue/prettier-config": "workspace:*",
7979
"@vorsteh-queue/tsconfig": "workspace:*",
80-
"eslint": "^9.38.0",
80+
"eslint": "^9.39.1",
8181
"next-validate-link": "1.6.3",
8282
"pagefind": "1.4.0",
8383
"postcss": "8.5.6",

apps/docs/src/app/(site)/(docs)/layout.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ export default async function DocsLayout(props: LayoutProps<"/">) {
3434
<SidebarInset className="bg-white dark:bg-secondary">
3535
<div className="flex flex-1 flex-col gap-4 pb-[calc(var(--footer-height)+1rem)]">
3636
<main className="flex w-full flex-1 flex-col transition-all duration-300 ease-in-out">
37-
{
38-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
39-
props.children
40-
}
37+
{props.children}
4138
</main>
4239
</div>
4340
</SidebarInset>

apps/docs/src/mdx-components.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ export function useMDXComponents() {
129129
return (
130130
<Alert variant={"default"} className="my-4">
131131
{title && <AlertTitle>{title}</AlertTitle>}
132-
<AlertDescription>{children}</AlertDescription>
132+
<AlertDescription className="block">{children}</AlertDescription>
133133
</Alert>
134134
)
135135
},
136136
Warning: ({ title, children }: { title?: string; children: ReactNode }) => {
137137
return (
138138
<Alert variant={"destructive"} className="my-4">
139139
{title && <AlertTitle>{title}</AlertTitle>}
140-
<AlertDescription>{children}</AlertDescription>
140+
<AlertDescription className="block">{children}</AlertDescription>
141141
</Alert>
142142
)
143143
},

examples/batch-processing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"postgres": "^3.4.7"
1616
},
1717
"devDependencies": {
18-
"drizzle-kit": "^0.31.5",
18+
"drizzle-kit": "^0.31.6",
1919
"tsx": "4.20.6",
2020
"typescript": "^5.9.3"
2121
}

0 commit comments

Comments
 (0)