Repository navigation
New drizzle-kit config and Plugins API #5201
Replies: 2 comments
|
A real-world scenario for We generate migrations in agent sessions and apply them unattended, in a pre-deploy step, with the server refusing to start while any migration is pending. The only gate between a generated file and production is that a session reviewed the SQL, and nothing in the toolchain ties applying to that review having happened. What we built: a migration is a draft until it ends with a review line, What the plugin API would need for this to live in a hook rather than a wrapper: A read-only pending list beside it, roughly On the destructive-statement TODO: the same hook is where we would attach a rows-touched report, replaying the batch inside a rolled-back transaction, so a data-losing statement is seen before the deploy applies it. |
|
I'm not quite sure if I understand the scope of this, but I want some way of extending the sorts of entities that drizzle-kit can manage. Particularly I'm interested in funcitons, triggers, comments, roles and permissions. eg I want to declare functions in my schema, and have the migration lifecycle be automated: // schema/functions.ts
import { sql } from 'drizzle-orm';
import { pgFunction } from 'drizzle-funcs';
export const orderTotal = pgFunction('order_total', {
args: [{ name: 'order_id', type: 'uuid' }],
returns: 'numeric',
language: 'sql',
volatility: 'stable',
security: 'invoker',
body: sql`select sum(price * qty) from order_items where order_id = $1`,
});
// queries.ts
import { desc, eq, gt } from 'drizzle-orm';
import { orders } from './schema/tables';
import { orderTotal } from './schema/functions';
const total = orderTotal(orders.id).as('total');
const rows = await db
.select({ id: orders.id, status: orders.status, total })
.from(orders)
.where(gt(orderTotal(orders.id), '100'))
.orderBy(desc(total));
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
import { definePlugin } from 'drizzle-funcs';
export default defineConfig({
dialect: 'postgresql',
schema: './schema',
out: './drizzle',
plugins: [
definePlugin(),
],
});The |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
While working on v1, we realized that this would be a great time to upgrade the
drizzle-kitconfig, remove legacy commands, and introduceplugins. These plugins would extenddrizzle-kitby hooking into kit lifecycles and controlling how the generate, migrate, pull, and push commands workThis discussion aims to showcase our thoughts on the updated config and
plugin api, along with all the possible lifecycle hooks we can think of as needed. We’d love to hear feedback and get ideas on how to improve itOld
drizzle-kitconfig optionsNew
drizzle-kitconfig optionsSo we will get a set of changes in the config:
"strict": truewill be enabled by default and removed from the config.extensionsFilters,tablesFilter, andschemaFilterwill be extended and moved underentities. This API will reproduce different settings for thedatabase entitiesyou may haveschemasandtableswill get 1 more api option - callback. You can add custom logic for filtering specific tables, views or schemas.Plugins API
This API is inspired by Astro integrations, and we’ve used the main API ideas from there. Here is an example of how you would define the
introspectimplementation.DrizzlePlugin will have plugin
nameand differenthooksimplementations you want to defineHere is a list of possible hooks we want to expose (together with their use cases)
All reactions