List of commands
Generate migrations
drizzle-kit generate:{dialect}
lets you generate migrations based on you DrizzleORM schema.
param | required | description |
---|---|---|
schema | yes | path to typescript schema file or folder with multiple schema files |
out | no | migrations folder, default=./drizzle |
config | no | config file path, default=drizzle.config.ts |
custom | no | generate empty SQL for custom migration |
breakpoints | no | SQL statements breakpoints, default=true |
$ drizzle-kit generate:pg
$ drizzle-kit generate:mysql
$ drizzle-kit generate:sqlite
// drizzle.config.ts
import type { Config } from "drizzle-kit";
export default {
schema: "./src/schema.ts",
out: "./drizzle",
} satisfies Config;
If you want to use custom named config file
$ drizzle-kit generate:pg --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit generate:pg --schema=./src/schema.ts --out=./drizzle
Generate an empty SQL migration file for custom migration.
$ drizzle-kit generate:pg --custom
Introspect / Pull
drizzle-kit introspect:{dialect}
command lets you pull DDL from existing database and generate schema.ts
file in matter of seconds.
Either connectionString
or user:password@host:port/db
params are mandatory
param | required | description |
---|---|---|
driver | yes | driver to use for querying (mysql2 , better-sqlite , libsql , turso ) |
out | no | migrations folder, default=./drizzle |
connectionString | no | database connection string |
user | no | database user |
password | no | database password |
host | no | host |
port | no | port |
database | no | database name |
config | no | config file path, default=drizzle.config.ts |
introspect-casing | no | strategy for JS keys creation in columns, tables, etc. (preserve , camel ) |
$ drizzle-kit introspect:pg
$ drizzle-kit introspect:mysql
$ drizzle-kit introspect:sqlite
import type { Config } from "drizzle-kit";
export default {
schema: "./src/schema/*",
out: "./drizzle",
driver: 'pg',
dbCredentials: {
connectionString: "postgresql://postgres:password@host:port/db",
}
} satisfies Config;
If you want to use custom named config file
$ drizzle-kit introspect:pg --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit introspect:pg --out=migrations/ --connectionString=postgresql://user:pass@host:port/db_name
$ drizzle-kit introspect:pg --out=migrations/ --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
Prototype / Push
drizzle-kit push:{dialect}
lets you push your schema changes directly to the
database and omit managing SQL migration files. This has proven to be very useful
for rapid local development(prototyping) and when working with remote databases like
Planetscale (opens in a new tab), Neon (opens in a new tab), Turso (opens in a new tab) and others.
Extended article on Turso and drizzle-kit push - read here (opens in a new tab)
Either connectionString
or user:password@host:port/db
params are required
drizzle-kit push
does not support PostgreSQL yet
param | required | description |
---|---|---|
schema | yes | path to typescript schema file or folder with multiple schema files |
driver | yes | driver to use for querying (mysql2 , better-sqlite , libsql , turso ) |
tablesFilter | no | table name filter |
connectionString | no | database connection string |
user | no | database user |
password | no | database password |
host | no | host |
port | no | port |
database | no | database name |
config | no | config file path, default=drizzle.config.ts |
verbose | no | print all queries that will be executed |
strict | no | always ask for an approve before pushing the schema |
$ drizzle-kit push:mysql
$ drizzle-kit push:sqlite
If you want to use custom named config file
$ drizzle-kit push:mysql --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit push:mysql --schema=src/schema.ts --connectionString=postgresql://user:pass@host:port/db_name
$ drizzle-kit push:mysql --schema=src/schema.ts --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
Drop migration
drizzle-kit drop
lets you delete previously generated migrations from migrations folder
Please don't delete any files in migrations folder manually, it might break drizzle-kit
param | required | description |
---|---|---|
out | no | migrations folder, default=./drizzle |
config | no | config file path, default=drizzle.config.ts |
$ drizzle-kit drop
If you want to use custom named config file
$ drizzle-kit drop --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit drop --out=drizzle
Maintain stale metadata
We're rapidly evolving Drizzle Kit APIs and from time to time there's a need to upgrade underlying metadata structure.
drizzle-kit up:{dialect}
is a utility command to keep all metadata up to date.
param | required | description |
---|---|---|
out | no | migrations folder, default=./drizzle |
config | no | config file path, default=drizzle.config.ts |
$ drizzle-kit up:pg
$ drizzle-kit up:mysql
$ drizzle-kit up:sqlite
If you want to use custom named config file
$ drizzle-kit up:pg --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit up:pg --out=drizzle
Check
drizzle-kit check:{dialect}
is a very powerfull tool for you to check consistency of your migrations.
That's extremely useful when you have multiple people on the project, altering database schema on different branches.
Drizzle Kit will check for all collisions and inconsistencies.
param | required | description |
---|---|---|
out | no | migrations folder, default=./drizzle |
config | no | config file path, default=drizzle.config.ts |
$ drizzle-kit check:pg
$ drizzle-kit check:mysql
$ drizzle-kit check:sqlite
If you want to use custom named config file
$ drizzle-kit check:pg --config=custom.config.ts
If you want to have all params as CLI options
$ drizzle-kit check:pg --out=drizzle
Drizzle Studio [NEW]
drizzle-kit studio
lets you launce Drizzle Studio database browser locally from you config file.
param | required | description |
---|---|---|
port | no | custom port |
verbose | no | log all sql statements |
drizzle-kit studio
drizzle-kit studio --port 3000 --verbose