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
src/schema.ts
import * as p from "drizzle-orm/mysql-core";export const users = p.mysqlTable("users", { id: p.int().primaryKey().autoincrement(), name: p.varchar({ length: 255 }),});
βββββββββββββββββββββββ β ~ drizzle-kit push β βββ¬ββββββββββββββββββββ β ββββββββββββββββββββββββββββ β Pull current datatabase schema ---------> β β β β β Generate alternations based on diff <---- β DATABASE β β β β β Apply migrations to the database -------> β β β ββββββββββββββββββββββββββββ β ββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββ create table `users` (`id` int AUTO_INCREMENT PRIMARY KEY, `name` varchar(255));
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:
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.
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:
print the planned SQL changes, without applying them (dry run)
force
auto-accept all data-loss statements
npm
yarn
pnpm
bun
npx drizzle-kit push --explain --verbose --force
yarn drizzle-kit push --explain --verbose --force
pnpm drizzle-kit push --explain --verbose --force
bunx drizzle-kit push --explain --verbose --force
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 postgresqlmysqlsqlitetursosinglestoremssqlcockroach
schema
required
Path to typescript schema file(s) or folder(s) with multiple schema files