Prisma Migrate is tied to Prisma. Raw SQL migrations are error-prone. Drizzle Kit generates SQL migrations from your TypeScript schema — type-safe, database-native, no lock-in.
What Is Drizzle Kit?
Drizzle Kit is the CLI companion to Drizzle ORM. It generates SQL migrations from your TypeScript schema, manages migration history, and provides a visual studio for your database.
Quick Start
npm install -D drizzle-kit
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
Define Schema
// src/db/schema.ts
import { pgTable, serial, text, timestamp, boolean, integer } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').unique().notNull(),
createdAt: timestamp('created_at').defaultNow(),
});
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
title: text('title').notNull(),
content: text('content'),
published: boolean('published').default(false),
authorId: integer('author_id').references(() => users.id),
createdAt: timestamp('created_at').defaultNow(),
});
Generate & Apply Migrations
# Generate migration from schema changes
npx drizzle-kit generate
# Creates: drizzle/0001_create_users_table.sql
# Pure SQL — review, edit, version control
# Apply migrations
npx drizzle-kit migrate
# Push schema directly (for development)
npx drizzle-kit push
Drizzle Studio
npx drizzle-kit studio
# Opens browser-based database GUI
# Browse data, edit rows, run queries
# No pgAdmin or DBeaver needed
Migration Output (Pure SQL)
-- drizzle/0001_create_users_table.sql
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"email" text NOT NULL,
"created_at" timestamp DEFAULT now(),
CONSTRAINT "users_email_unique" UNIQUE("email")
);
CREATE TABLE IF NOT EXISTS "posts" (
"id" serial PRIMARY KEY NOT NULL,
"title" text NOT NULL,
"content" text,
"published" boolean DEFAULT false,
"author_id" integer REFERENCES "users"("id"),
"created_at" timestamp DEFAULT now()
);
Why Drizzle Kit
| Feature | Drizzle Kit | Prisma Migrate | Knex |
|---|---|---|---|
| Output | Pure SQL | Prisma-specific | JS files |
| Review migrations | SQL files | Shadow DB | JS files |
| Schema language | TypeScript | Prisma DSL | JS |
| Studio | Built-in | Paid | No |
| Lock-in | None | Prisma ecosystem | None |
Get Started
- Documentation
- GitHub — 25K+ stars
Managing scraped data databases? My Apify actors work with any database. Custom solutions: spinov001@gmail.com
Top comments (0)