Make sure to first go through Drizzle get started and migration foundamentals and pick SQL migration flow that suites your business needs best.
Migrations with Drizzle Kit
This guide assumes familiarity with:
Drizzle Kit is a CLI tool for managing SQL database migrations with Drizzle.
npm
yarn
pnpm
bun
IMPORTANT
Based on your schema, Drizzle Kit letβs you generate and run SQL migration files, push schema directly to the database, pull schema from database, spin up drizzle studio and has a couple of utility commands.
npm
yarn
pnpm
bun
drizzle-kit generate | lets you generate SQL migration files based on your Drizzle schema either upon declaration or on subsequent changes, see here. |
drizzle-kit migrate | lets you apply generated SQL migration files to your database, see here. |
drizzle-kit pull | lets you pull(introspect) database schema, convert it to Drizzle schema and save it to your codebase, see here |
drizzle-kit push | lets you push your Drizzle schema to database either upon declaration or on subsequent schema changes, see here |
drizzle-kit studio | will connect to your database and spin up proxy server for Drizzle Studio which you can use for convenient database browsing, see here |
drizzle-kit check | will walk through all generate migrations and check for any race conditions(collisions) of generated migrations, see here |
drizzle-kit up | used to upgrade snapshots of previously generated migrations, see here |
Drizzle Kit is configured through drizzle.config.ts configuration file or via CLI params.
Itβs required to at least provide SQL dialect
and schema
path for Drizzle Kit to know how to generate migrations.
simple config
extended config
You can provide Drizzle Kit config path via CLI param, itβs very useful when you have multiple database stages or multiple databases or different databases on the same project:
npm
yarn
pnpm
bun