Apply generated migrations
Code-first schema workflow
Drizzle ORM · Command
drizzle-kit migrate applies SQL migrations generated by drizzle-kit generate. It checks migration history, runs only pending migrations, and records successful applications.
The command reads SQL files from the migrations folder, checks the database migration history, selects migrations that have not run yet, executes them, and records successful applications. Configure the dialect and database credentials in drizzle.config.ts or pass them as command-line options.
npx drizzle-kit migrate [options]| Name | Type | Description |
|---|---|---|
dialect | CLI option / configuration | Database dialect, such as postgresql, mysql, sqlite, or cockroach. |
url | CLI option / configuration | Database connection credentials, commonly supplied as a URL. |
config | CLI option | Path to an alternative Drizzle Kit configuration file. |
Applies pending SQL migrations and records successfully applied migrations in the database.
npx drizzle-kit migrate --config=drizzle-prod.config.tsRuns pending SQL migrations using the specified Drizzle Kit configuration.
Code-first schema workflow
Environment-specific deployment
Automated database setup
It reads the migration SQL files, retrieves the migration history, identifies unapplied migrations, executes them, and logs the results. This makes repeated runs apply only migrations that are still pending.
Follow-up: What must be configured before running it? The command needs both a database dialect and connection credentials, supplied in drizzle.config.ts or as CLI options.
The command applies SQL migrations generated by drizzle-kit generate. It is intended for the code-first migration workflow, where the Drizzle schema is used to produce migration files before they are applied.
Follow-up: How could generated migrations be applied instead? They can also be run with drizzle-orm's migrate(), external migration tooling, or directly against the database.
A successful run persists migration records in the database. The default log table is named __drizzle_migrations in the drizzle schema.
Follow-up: What operational concern follows from this? The database must preserve that log because it is used to distinguish already-applied migrations from pending ones.
drizzle-kit generatedrizzle-kit pushdrizzle-kit pulldrizzle-kit exportdrizzle-orm migrate()