Skip to content
Back to Deployment

Drizzle Migrate

Lightweight TypeScript-first ORM migrations for Postgres, MySQL, SQLite.

CI/CDIntermediate

Why

Drizzle is a lightweight ORM with full TypeScript inference and no codegen. Migrations are SQL files, easy to review and apply.

Smaller bundle than Prisma.

When

Use Drizzle for edge/serverless apps needing lightweight ORM. Avoid if you need Prisma Studio GUI.

How

1. Schema — schema.ts with pgTable/mysqlTable 2. Config — drizzle.config.ts with dialect + credentials 3. Generate — npx drizzle-kit generate (creates SQL migration) 4. Migrate — npx drizzle-kit migrate (applies) 5. Push — npx drizzle-kit push (dev, no migration files) 6. Studio — npx drizzle-kit studio (GUI) 7. Introspect — npx drizzle-kit introspect (existing DB)

Example

// schema.ts import { pgTable, serial, varchar } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: serial("id").primaryKey(), email: varchar("email").notNull().unique(), }); // drizzle.config.ts export default { schema: "./schema.ts", out: "./drizzle", dialect: "postgresql", dbCredentials: { url: process.env.DATABASE_URL! }, }; # Generate and migrate npx drizzle-kit generate # creates SQL in drizzle/ npx drizzle-kit migrate # applies migrations // Use in code import { drizzle } from "drizzle-orm/node-postgres"; const db = drizzle(pool, { schema });

Common Problems

  • ⚠Migration order — Drizzle uses timestamps, ensure clock sync across team
  • ⚠Push in production — push skips migration files, use migrate in prod
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Use generate + migrate in production — reviewable SQL files
  • ✓Use push only in development — fast iteration, no migration history
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ