out configuration property
The out property defines the output folder for SQL migration files, JSON snapshots of schema, and schema.ts from drizzle-kit pull command. Type: string or string[]. Default: 'drizzle'. Commands: generate, pull, migrate, check, up.
dbCredentials configuration for MSSQL
The dbCredentials property specifies database connection credentials. For MSSQL, use either a connection string format (url: 'mssql://user:password@host:3306/db') or connection params (database, password, port, server, user, and options object with encrypt and trustServerCertificate properties). Type: object. Default: none (required for certain commands). Commands: push, pull, migrate, studio.
migrations configuration property
The migrations property configures the migrations log table and schema. It has two properties: table (string, default '__drizzle_migrations') and schema (string, default 'drizzle'). When running drizzle-kit migrate, Drizzle records successfully applied migrations in the database in the log table. Type: { table: string, schema: string }. Default: { table: '__drizzle_migrations', schema: 'drizzle' }. Commands: migrate, push, pull.
introspect configuration property for casing
The introspect property configures the drizzle-kit pull command. The casing property is responsible for in-code column keys casing. It accepts 'preserve' or 'camel'. Type: { casing: 'preserve' | 'camel' }. Default: { casing: 'camel' }. Commands: pull.
schemaFilter configuration property
The schemaFilter property lets you specify glob-based schema names filter for drizzle-kit push and pull commands. By default, all schemas are managed. Type: string[]. Default: none. Commands: push, pull. Example: ['dbo', 'schema1', 'schema2'].
verbose configuration property
The verbose property prints all SQL statements during drizzle-kit push command. Type: boolean. Default: false. Commands: pull.
breakpoints configuration property
The breakpoints property controls whether Drizzle Kit automatically embeds '--> statement-breakpoint' into generated SQL migration files. This is necessary for databases that do not support multiple DDL alternation statements in one transaction. Type: boolean. Default: true. Commands: generate, pull.
Migration folder structure in Drizzle Kit
The migration folder (specified by the out property) contains subdirectories with names like timestamps (e.g., 20242409125510_premium_mister_fear) and .sql migration files.
drizzle-kit check command purpose
The drizzle-kit check command lets you check consistency of your generated SQL migrations history. It is extremely useful when multiple developers work on the project and alter database schema on different branches.
drizzle-kit check dialect requirement
The drizzle-kit check command requires you to specify a dialect, which can be provided either via the drizzle.config.ts config file or via CLI options using --dialect.
drizzle-kit check with config file
To run drizzle-kit check with a config file, define the dialect in drizzle.config.ts and run: npx drizzle-kit check
drizzle-kit check with CLI dialect option
To run drizzle-kit check with CLI options, use: npx drizzle-kit check --dialect=mssql
drizzle-kit check --ignore-conflicts option
The --ignore-conflicts flag allows the check command to skip commutativity checks and bypass them. This option should rarely be needed; if you find yourself using it, it may indicate a bug in drizzle-kit that should be reported.
drizzle-kit check CLI configuration options
The drizzle-kit check command accepts the following CLI configuration options: dialect (required) - database dialect being used; out (optional) - migrations folder with default value ./drizzle; config (optional) - configuration file path with default value drizzle.config.ts
drizzle-kit check with custom migrations folder
To specify a custom migrations folder with drizzle-kit check, use: drizzle-kit check --dialect=mssql --out=./migrations-folder
drizzle-kit export command purpose
The drizzle-kit export command lets you export SQL representation of a Drizzle schema and print the SQL DDL representation to console. It is designed to cover the codebase-first approach of managing Drizzle migrations.
drizzle-kit export required options
The drizzle-kit export command requires both dialect and schema path options. These can be set either via the drizzle.config.ts config file or via CLI options.
drizzle-kit export how it works
The drizzle-kit export command triggers a sequence of events: (1) It reads through Drizzle schema file(s) and composes a JSON snapshot of the schema, (2) based on the current JSON snapshot it generates SQL DDL statements, (3) output SQL DDL statements to console.
drizzle-kit export with config file example
To export with a config file, create drizzle.config.ts with dialect and schema properties, then run: npx drizzle-kit export
drizzle-kit export with CLI options example
To export with CLI options instead of a config file, run: npx drizzle-kit export --dialect=mssql --schema=./src/schema.ts
drizzle-kit export schema file paths
You can have a single schema.ts file or multiple schema files spread across the project. Drizzle Kit requires you to specify path(s) to them as a glob pattern via the schema configuration option.
drizzle-kit export with multiple config files
You can have multiple config files in a project when you have multiple database stages, multiple databases, or different databases on the same project. Use the --config flag to specify which config file to use: npx drizzle-kit export --config=drizzle-dev.config.ts or npx drizzle-kit export --config=drizzle-prod.config.ts
drizzle-kit export CLI options reference
drizzle-kit export has the following configuration options: dialect (required) - database dialect, one of the supported dialects; schema (required) - path to typescript schema file(s) or folder(s) with multiple schema files; config (optional) - configuration file path, default is drizzle.config.ts; --sql (optional) - generating SQL representation of Drizzle Schema, default is true.
drizzle-kit export complete example
Example showing drizzle-kit export workflow: Create drizzle.config.ts with dialect: 'mssql' and schema: './src/schema.ts'. Create schema.ts with: import { mssqlTable, int, text } from 'drizzle-orm/mssql-core'; export const users = mssqlTable('users', { id: int().primaryKey().identity(), email: text().notNull(), name: text() }); Then run: npx drizzle-kit export --config=./configs/drizzle.config.ts. This outputs SQL: CREATE TABLE [users] ( [id] int IDENTITY(1, 1), [email] text NOT NULL, [name] text, CONSTRAINT [users_pkey] PRIMARY KEY([id]) );
drizzle-kit pull configuration requirements
drizzle-kit pull requires specification of dialect and either a database connection url or user:password@host:port/db params. These can be provided via drizzle.config.ts or CLI options.
drizzle-kit pull command purpose
drizzle-kit pull introspects an existing database schema and generates a schema.ts Drizzle schema file. It is designed to support a database-first approach to Drizzle migrations.
drizzle-kit pull workflow steps
When drizzle-kit pull runs, it first pulls the database schema (DDL) from the existing database, then generates a schema.ts Drizzle schema file and saves it to the out folder.
drizzle-kit pull with config file
To run drizzle-kit pull with a config file, define dialect and dbCredentials.url in drizzle.config.ts, then execute 'npx drizzle-kit pull' without additional arguments.
drizzle-kit pull with CLI options
To run drizzle-kit pull via CLI, use 'npx drizzle-kit pull --dialect=mssql --url=mssql://user:password@host:port/dbname' to specify dialect and connection details directly.
Multiple drizzle-kit config files
You can have multiple config files in a project for different database stages or databases. Use 'npx drizzle-kit pull --config=drizzle-dev.config.ts' or '--config=drizzle-prod.config.ts' to specify which config to use.
drizzle-kit pull --init flag
The --init flag marks the pulled schema as an applied migration in the database, so subsequent migrations are diffed against this initial one. Usage: 'npx drizzle-kit pull --init'
drizzle-kit pull default table and schema filtering
By default, drizzle-kit pull manages all tables in all schemas. You can restrict this using tablesFilter and schemaFilter options.
tablesFilter option in drizzle-kit pull
The tablesFilter option accepts a glob-based table names filter, such as ['users', 'user_info'] or 'user*'. Default is '*' (all tables).
schemaFilter option in drizzle-kit pull
The schemaFilter option accepts a glob-based schema names filter, such as ['dbo', 'drizzle'] or 'drizzle*'. Default is '*' (all schemas).
drizzle-kit pull CLI options table
drizzle-kit pull accepts the following CLI options: dialect (required), out (default './drizzle'), url, user, password, host, port, database, config (default 'drizzle.config.ts'), introspect-casing ('preserve' or 'camel'), tablesFilter, and schemaFilter (default '['*']').
introspect-casing option in drizzle-kit pull
The introspect-casing option controls the strategy for JS keys creation in columns, tables, and other schema elements. Valid values are 'preserve' and 'camel'.
drizzle-kit pull example with tablesFilter
Example: 'npx drizzle-kit pull --dialect=mssql --tablesFilter='user*' --url=mssql://user:password@host:port/dbname' pulls only tables matching the 'user*' pattern.