Skip to content

Commit 2248ea7

Browse files
committed
more docs
1 parent 9f040b7 commit 2248ea7

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

packages/docs/content/docs/adapters.mdx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,92 @@ To generate new migrations:
117117
bun run generate:postgres
118118
```
119119

120+
## Integrating Duron Schema into Your Own Drizzle Schema
121+
122+
If you're already using Drizzle ORM in your project and want to manage all migrations together, you can include Duron's schema in your own Drizzle schema instead of using Duron's automatic migrations.
123+
124+
### Step 1: Import and Include Duron's Schema
125+
126+
In your Drizzle schema file (e.g., `schema.ts`), import `createSchema` from Duron and include the tables:
127+
128+
```ts
129+
import createSchema from 'duron/adapters/postgres/schema'
130+
131+
// Create Duron's schema with your desired schema name
132+
const { jobsTable, jobStepsTable } = createSchema('public')
133+
134+
// Export the tables so they can be used by Drizzle Kit
135+
export { jobsTable, jobStepsTable }
136+
137+
// Also export your other tables
138+
export const users = pgTable('users', {
139+
// ... your table definition
140+
})
141+
```
142+
143+
**Note:** The schema name you pass to `createSchema()` (e.g., `'public'`) must match the `schema` option you provide to the adapter.
144+
145+
### Step 2: Configure the Adapter
146+
147+
When creating the adapter, set `migrateOnStart: false` to disable Duron's automatic migrations:
148+
149+
```ts
150+
import { duron } from 'duron'
151+
import { postgresAdapter } from 'duron/adapters/postgres'
152+
153+
const client = duron({
154+
database: postgresAdapter({
155+
connection: process.env.DATABASE_URL!,
156+
schema: 'public', // Match the schema name used in createSchema
157+
migrateOnStart: false, // Disable automatic migrations
158+
}),
159+
actions: {
160+
sendEmail,
161+
},
162+
})
163+
```
164+
165+
### Step 3: Generate and Run Migrations
166+
167+
Since you've disabled Duron's automatic migrations, you'll need to generate and run migrations using your own Drizzle Kit configuration:
168+
169+
1. **Configure Drizzle Kit** to include your schema file:
170+
171+
```ts
172+
// drizzle.config.ts
173+
import { defineConfig } from 'drizzle-kit'
174+
175+
export default defineConfig({
176+
schema: './schema.ts', // Your schema file that includes Duron's tables
177+
out: './drizzle',
178+
dialect: 'postgresql',
179+
})
180+
```
181+
182+
2. **Generate migrations** using Drizzle Kit:
183+
184+
```bash
185+
drizzle-kit generate
186+
```
187+
188+
3. **Run migrations** using your preferred method (e.g., Drizzle Kit, a migration tool, or manually):
189+
190+
```bash
191+
drizzle-kit migrate
192+
```
193+
194+
### Benefits
195+
196+
- **Unified migrations**: All your database migrations (including Duron's) are managed in one place
197+
- **Better control**: You have full control over when and how migrations are run
198+
- **Schema consistency**: Duron's tables are part of your main schema, making it easier to manage relationships and queries
199+
200+
### Important Notes
201+
202+
- Make sure the `schema` option in the adapter matches the schema name you pass to `createSchema()`
203+
- Always set `migrateOnStart: false` when using this approach
204+
- The `jobsTable` and `jobStepsTable` must be exported from your schema file for Duron to work correctly
205+
120206
## Custom Adapters
121207

122208
You can create custom adapters by extending the `Adapter` class:

0 commit comments

Comments
 (0)