Bootstrap a database schema
Create the initial migration from a newly declared Drizzle schema.
Drizzle ORM · Command
Generates SQL migrations from a Drizzle schema by comparing its current snapshot with the latest migration snapshot. It writes the resulting migration files to the configured output directory.
The command reads the current Drizzle schema, compares it with the latest schema snapshot in the migrations directory, derives the differences, and writes a timestamped migration containing migration.sql and snapshot.json. Configure options in drizzle.config.ts or pass them on the command line.
drizzle-kit generate [options]| Name | Type | Description |
|---|---|---|
dialect | required string | Database dialect; supported values include postgresql, mysql, sqlite, turso, singlestore, mssql, and cockroach. |
schema | required path or glob | Path to one or more TypeScript schema files or a directory containing schema files. |
out | optional path | Directory for generated migrations; defaults to ./drizzle. |
config | optional path | Path to the Drizzle configuration file; defaults to drizzle.config.ts. |
breakpoints | optional boolean | Controls SQL statement breakpoints; defaults to true. |
Creates a timestamped migration directory containing migration.sql and snapshot.json.
npx drizzle-kit generate --dialect=postgresql --schema=./src/schema.tsGenerates a migration from the TypeScript schema and writes it to the configured migrations directory.
Create the initial migration from a newly declared Drizzle schema.
Turn subsequent TypeScript schema changes into versioned SQL migrations.
Run generation in an automated pipeline by passing configuration as CLI flags.
drizzle-kit generate do?It reads the schema, creates a JSON snapshot, compares that snapshot with the latest previous migration snapshot, and generates SQL from the differences. The generated files are saved in the migration folder.
Follow-up: How would you apply the generated migration? Use drizzle-kit migrate or Drizzle ORM’s migrate() function.
The command requires dialect and schema. These can be configured in drizzle.config.ts or passed as CLI options.
Follow-up: What is a useful optional output setting? out changes the migrations output folder; its documented default is ./drizzle.
A schema change is compared with the most recent migration snapshot, and the resulting SQL is written to a timestamped migration directory. The snapshot preserves the schema state used for later comparisons.
Follow-up: Can all options be supplied without a config file? Yes; the documentation says CLI options can be used when necessary, including in CI/CD pipelines.
drizzle-kit migratedrizzle-kit pushdrizzle-kit pulldrizzle.config.tsmigrate()