Skip to main content
Drizzle Kit is the essential CLI companion for Drizzle ORM that handles database migrations, schema introspection, and developer tooling. It automatically generates SQL migrations by comparing your schema changes and handles ~95% of edge cases like renames and deletions through intelligent prompting.

Installation

Configuration

Create a drizzle.config.ts file in your project root:
drizzle.config.ts
You can also use a drizzle.config.js file or specify configuration via CLI options.

Core Commands

Generate Migrations

Generate SQL migration files from your schema changes:
How it works:
  1. Drizzle Kit reads your schema file
  2. Compares it with the previous snapshot (if exists)
  3. Generates SQL migration files for the differences
  4. Prompts you for input on ambiguous cases (renames, etc.)
Options:
  • --config - Path to config file
  • --schema - Path to schema file(s)
  • --out - Output directory for migrations (default: drizzle)
  • --name - Custom migration name
  • --custom - Create empty migration file for custom SQL
  • --dialect - Database dialect
  • --breakpoints - Add SQL breakpoints
Example:

Push Schema

Push schema changes directly to the database without generating migration files:
Push is designed for rapid prototyping and local development. Always use migrations in production environments.
Options:
  • --strict - Always ask for confirmation
  • --force - Auto-approve all data loss statements
  • --verbose - Print all SQL statements
Use cases:
  • Local development and prototyping
  • Testing schema changes quickly
  • Syncing schema to preview environments

Apply Migrations

Apply pending migrations to your database:
This command:
  1. Connects to your database
  2. Creates migrations table if it doesn’t exist
  3. Runs all pending migrations in order
  4. Updates the migrations table

Introspect Database

Generate Drizzle schema from an existing database (also known as pull):
Options:
  • --introspect-casing - Choose casing: camel or preserve
  • --tablesFilter - Filter specific tables
  • --schemaFilters - Filter specific schemas
Example:
This generates TypeScript schema files from your database structure, perfect for:
  • Migrating to Drizzle from another ORM
  • Working with existing databases
  • Keeping schema in sync with database changes

Check Migrations

Validate migration files for consistency:
Verifies that migration files are valid and haven’t been corrupted.

Drop Migration

Remove the last generated migration:
This only removes the migration file, it doesn’t rollback applied migrations in the database.

Database Dialects

Drizzle Kit supports multiple database dialects:
drizzle.config.ts
Supports drivers:
  • aws-data-api - AWS RDS Data API
  • pglite - PGlite

Migration Workflow

1

Define your schema

Create or modify your schema file:
src/db/schema.ts
2

Generate migration

Run the generate command:
This creates a migration file in your output directory:
drizzle/0000_users_table.sql
3

Review migration

Inspect the generated SQL to ensure it matches your intentions. You can edit the migration file if needed.
4

Apply migration

Run the migrate command to apply changes:
Or apply migrations programmatically in your application:

Common Patterns

Environment-based Configuration

drizzle.config.ts

Multiple Schema Files

drizzle.config.ts

Custom Migration Prefixes

drizzle.config.ts

Table Filters for Introspection

drizzle.config.ts

Package Scripts

Add these scripts to your package.json for convenience:
package.json

Best Practices

1

Version control migrations

Always commit migration files to version control. They represent your database history.
2

Never edit applied migrations

Once a migration has been applied to production, create a new migration for changes instead of editing the existing one.
3

Test migrations

Test migrations in development and staging before applying to production.
4

Use push for development

Use drizzle-kit push for rapid development, but switch to migrations before deploying.
5

Review generated SQL

Always review the generated SQL before applying migrations to production.

Troubleshooting

Migration conflicts

If you encounter migration conflicts when working in a team:

Connection issues

Verify your database credentials:
The verbose flag shows connection details and SQL statements.

Schema validation

If you get schema validation errors, ensure your drizzle-orm version is compatible:

Next Steps

Drizzle Studio

Explore your database with the visual database browser

Migrations Guide

Learn advanced migration patterns and strategies