Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Command

drizzle-kit generate

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.

How it works

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.

Syntax

drizzle-kit generate [options]

Parameters

NameTypeDescription
dialectrequired stringDatabase dialect; supported values include postgresql, mysql, sqlite, turso, singlestore, mssql, and cockroach.
schemarequired path or globPath to one or more TypeScript schema files or a directory containing schema files.
outoptional pathDirectory for generated migrations; defaults to ./drizzle.
configoptional pathPath to the Drizzle configuration file; defaults to drizzle.config.ts.
breakpointsoptional booleanControls SQL statement breakpoints; defaults to true.

Returns

Creates a timestamped migration directory containing migration.sql and snapshot.json.

Key points

  • Use the command to create SQL migrations from the declared Drizzle schema.
  • The first stage records the current schema as a JSON snapshot.
  • Previous migration snapshots provide the baseline for detecting changes.
  • The schema diff determines the SQL statements placed in the new migration.
  • A configuration file is the recommended way to define command settings.
  • CLI flags are available when configuration must be supplied dynamically.

Common mistakes

  • Both dialect and schema are required; provide them through drizzle.config.ts or CLI options.
  • Generation creates both the SQL migration and schema snapshot in the migration output directory.

Example: Generate a PostgreSQL migration

npx drizzle-kit generate --dialect=postgresql --schema=./src/schema.ts

Generates a migration from the TypeScript schema and writes it to the configured migrations directory.

When to use it

Bootstrap a database schema

Create the initial migration from a newly declared Drizzle schema.

Track schema evolution

Turn subsequent TypeScript schema changes into versioned SQL migrations.

Generate migrations in CI/CD

Run generation in an automated pipeline by passing configuration as CLI flags.

Interview questions

QWhat does 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.

QWhich inputs are required?

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.

QHow does the command detect schema changes?

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 migrate
  • drizzle-kit push
  • drizzle-kit pull
  • drizzle.config.ts
  • migrate()

Source: Drizzle ORM - `generate`. Checked 2026-10-16.