drizzle-kit push lets you literally push your schema and subsequent schema changes directly to the
database while omitting SQL files generation, it’s designed to cover code first
approach of Drizzle migrations.
How it works under the hood?
When you run Drizzle Kit push command it will:
Read through your Drizzle schema file(s) and compose a json snapshot of your schema
Pull(introspect) database schema
Based on differences between those two it will generate SQL migrations
Apply SQL migrations to the database
It’s the best approach for rapid prototyping and we’ve seen dozens of teams
and solo developers successfully using it as a primary migrations flow in their production applications.
It pairs exceptionally well with blue/green deployment strategy and serverless databases like
Planetscale, Neon, Turso and others.
drizzle-kit push requires you to specify dialect, path to the schema file(s) and either
database connection url or user:password@host:port/db params, you can provide them
either via drizzle.config.ts config file or via CLI options:
With config file
With CLI options
Schema files path
You can have a single schema.ts file or as many schema files as you want spread out across the project.
Drizzle Kit requires you to specify path(s) to them as a glob via schema configuration option.
Example 1
Example 2
Example 3
Example 4
Multiple configuration files in one project
You can have multiple config files in the project, it’s very useful when you have multiple database stages or multiple databases or different databases on the same project:
npm
yarn
pnpm
bun
Specifying database driver
IMPORTANT
Expo SQLite and OP SQLite are on-device(per-user) databases, there’s no way to push migrations there.
For embedded databases Drizzle provides embedded migrations - check out our get started guide.
Drizzle Kit does not come with a pre-bundled database driver,
it will automatically pick available database driver from your current project based on the dialect - see discussion.
Mostly all drivers of the same dialect share the same set of connection params,
as for exceptions like aws-data-api, pglight and d1-http - you will have to explicitly specify driver param.
AWS Data API
PGLite
Cloudflare D1 HTTP
Including tables, schemas and extensions
drizzle-kit push will by default manage all tables in public schema.
You can configure list of tables, schemas and extensions via tablesFilters, schemaFilter and extensionFilters options.
tablesFilter
glob based table names filter, e.g. ["users", "user_info"] or "user*". Default is "*"
schemaFilter
Schema names filter, e.g. ["public", "drizzle"]. Default is ["public"]
extensionsFilters
List of installed database extensions, e.g. ["postgis"]. Default is []
Let’s configure drizzle-kit to only operate with all tables in public schema
and let drizzle-kit know that there’s a postgis extension installed,
which creates it’s own tables in public schema, so drizzle can ignore them.
Extended list of configurations
drizzle-kit push has a list of cli-only options
verbose
print all SQL statements prior to execution
strict
always ask for approval before executing SQL statements
force
auto-accept all data-loss statements
npm
yarn
pnpm
bun
We recommend configuring drizzle-kit through drizzle.config.ts file,
yet you can provide all configuration options through CLI if necessary, e.g. in CI/CD pipelines, etc.
dialect
required
Database dialect, one of postgresqlmysqlsqliteturso
schema
required
Path to typescript schema file(s) or folder(s) with multiple schema files
driver
Drivers exceptions aws-data-apid1-httppglight
tablesFilter
Table name filter
schemaFilter
Schema name filter. Default: ["public"]
extensionsFilters
Database extensions internal database filters
url
Database connection string
user
Database user
password
Database password
host
Host
port
Port
database
Database name
config
Config file path, default=drizzle.config.ts
npm
yarn
pnpm
bun
Extended example
Let’s declare drizzle schema in the project and push it to the database via drizzle-kit push command
drizzle.config.ts
src/schema.ts
Now let’s run
it will pull existing(empty) schema from the database and generate SQL migration and apply it under the hood