Itβs designed to cover code first approach of managing Drizzle migrations.
You can apply generated migrations using drizzle-kit migrate, using drizzle-ormβs migrate(),
using external migration tools like bytebase or running migrations yourself directly on the database.
drizzle-kit generate command requires you to provide both dialect and schema path options,
you can set 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:
You can generate empty migration files to write your own custom SQL migrations
for DDL alternations currently not supported by Drizzle Kit or data seeding. Extended docs on custom migrations - see here
-- ./drizzle/20242409125510_seed/migration.sqlINSERT INTO `users` (`name`) VALUES('Dan');INSERT INTO `users` (`name`) VALUES('Andrew');INSERT INTO `users` (`name`) VALUES('Dandrew');
Ignore conflicts
In case you need generate command to skip commutativity checks and bypass it, you can use --ignore-conflicts. If there is a situation you want to use it, then
there is a big chance that drizzle-kit didnβt check migrations right and itβs a bug. Please report us your case, so we can fix it
drizzle-kit generate --ignore-conflicts
Extended list of available configurations
drizzle-kit generate has a list of cli-only options
custom
generate empty SQL for custom migration
name
generate migration with custom name
ignore-conflicts
skip commutativity conflict checks, default is false
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
out
Migrations output folder, default is ./drizzle
config
Configuration file path, default is drizzle.config.ts
breakpoints
SQL statements breakpoints, default is true
Extended example
Example of how to create a custom SQLite migration file named 0001_seed-users.sql
with Drizzle schema located in ./src/schema.ts and migrations folder named ./migrations instead of default ./drizzle.
We will also place drizzle config file in the configs folder.
-- ./drizzle/20242409125510_seed-users/migration.sqlINSERT INTO `users` (`name`) VALUES('Dan');INSERT INTO `users` (`name`) VALUES('Andrew');INSERT INTO `users` (`name`) VALUES('Dandrew');