Skip to main content
Drizzle Kit generates SQL migration files with metadata for tracking and applying database schema changes.

Migration Files

File Structure

Migrations are stored in the output directory (default: drizzle/) with the following structure:

SQL Migration File

Generated SQL files contain DDL statements with optional breakpoints:
Breakpoints (--> statement-breakpoint):
  • Enable sequential execution of statements
  • Required for MySQL, SQLite, and SingleStore (no multi-statement transactions)
  • Optional for PostgreSQL (supports multi-statement transactions)

Migration Metadata

Journal File (meta/_journal.json)

Tracks all migrations in order:
string
Drizzle Kit metadata format version
string
Database dialect: postgresql, mysql, sqlite, etc.
array
List of migration entries in chronological order
number
Sequential migration index
string
Migration filename (without .sql)
number
Unix timestamp (milliseconds) when migration was created
boolean
Whether migration uses statement breakpoints

Snapshot File (meta/XXXX_snapshot.json)

Complete schema snapshot at migration time:
Snapshots enable:
  • Detecting schema changes between migrations
  • Generating accurate diff SQL
  • Validating migration consistency

Migration Workflow

1. Generate Migration

Detect schema changes and create migration:
Process:
  1. Reads current Drizzle schema from schema files
  2. Compares with latest snapshot in meta/
  3. Generates SQL diff statements
  4. Creates new migration file with timestamp/index
  5. Updates _journal.json and creates new snapshot

2. Review Migration

Inspect generated SQL before applying:
Check for:
  • Correct DDL statements
  • Data migration needs
  • Potential data loss (DROP statements)
  • Index creation order

3. Apply Migration

Execute migrations against database:
Process:
  1. Connects to database using dbCredentials
  2. Creates migrations table if not exists
  3. Queries applied migrations from database
  4. Applies pending migrations in order
  5. Records each migration in migrations table

4. Verify Changes

Open Drizzle Studio to verify:

Programmatic API

Use migration functions directly in your application.

PostgreSQL

MySQL

SQLite

Turso (LibSQL)

Migration Options

string
required
Path to migrations directory
string
default:"__drizzle_migrations"
Custom migrations tracking table name
string
default:"drizzle"
PostgreSQL: Custom schema for migrations table

Custom Migrations

Generate Empty Migration

Create migration file for manual SQL:
Generated file:
Add your SQL statements:

Data Migrations

Combine DDL and data changes:

Migration Prefixes

Control migration file naming:

Index (default)

Config:

Timestamp

Config:

Unix Timestamp

Config:

Supabase Format

Compatible with Supabase migration format. Config:

No Prefix

Config:
Using none requires unique migration names and careful ordering.

Migration Management

Drop Migration

Remove the last migration:
Interactive prompt:
This:
  • Removes migration SQL file
  • Removes snapshot file
  • Updates _journal.json
  • Does NOT revert applied migrations in database
To revert database changes, manually create a new migration or restore from backup.

Check Migrations

Validate migration consistency:
Verifies:
  • Migration files exist for all journal entries
  • Snapshot files are valid JSON
  • No duplicate migration indices
  • SQL syntax is parseable

Upgrade Migrations

Update migration format after Drizzle Kit upgrades:
This updates:
  • Metadata version in snapshots
  • Journal format
  • Snapshot schema structure
Preserves:
  • SQL migration files (unchanged)
  • Migration order
  • Applied migrations in database

Best Practices

1. Version Control

Commit all migration files:

2. Review Before Apply

Always review generated SQL:

3. One-Way Migrations

Migrations are forward-only. To undo:
Manually write rollback SQL:

4. Test Migrations

Test on development database first:

5. Backup Before Migration

Always backup production before migrating:

6. Handle Data Migration

For complex data transformations:

7. Use Named Migrations

Descriptive names for clarity:

Troubleshooting

Migration Already Applied

Error: Migration has already been applied Solution: Check migrations table:
Manually remove if needed (use with caution).

Conflicting Migrations

Error: Migration conflict detected Solution:
  1. Pull latest migrations from version control
  2. Regenerate migration with latest schema
  3. Resolve conflicts manually

Breakpoint Errors (MySQL/SQLite)

Error: Multi-statement execution not supported Solution: Enable breakpoints:

Snapshot Mismatch

Error: Schema snapshot doesn’t match database Solution:
  1. Ensure all migrations are applied: drizzle-kit migrate
  2. Regenerate snapshot: drizzle-kit generate
  3. Or pull fresh schema: drizzle-kit pull

Production Deployment

Run migrations on application startup:
Or use dedicated migration script:
Package.json: