Configuring Drizzle kit
Configuration
By default, Drizzle reads the drizzle.config.ts
file located in the project’s root folder.
If you need to specify a different configuration file, you can utilize the --config=<path>
command-line option after any drizzle-kit command.
Drizzle Kit supports multiple formats for the configuration file, including .ts
, .js
.
This flexibility allows you to choose the format that best suits your needs and preferences.
Here are some examples of each file format usage:
Typescript example
JavaScript example
Options
dialect
- Type:
'postgresql' | 'mysql' | 'sqlite'
- Commands: all commands
Current param is available in [email protected]
and higher. In previous versions you should not use this param
The dialect
parameter is responsible for explicitly providing a databse dialect you are using
for all the commands
Usage
schema
- Type:
string | string[]
- Commands:
generate
,check
,up
,push
,drop
schema
param lets you define where your schema file/files live.
You can have as many separate schema files as you want and define paths to them using
glob
or array of globs syntax.
Usage
out
- Type:
string | string[]
- Default:
drizzle
- Commands:
generate
,check
,up
,drop
,introspect
,migrate
The out
parameter allows you to define the folder for your migrations.
In this folder, drizzle-kit will:
- Store migration files,
meta
, andjournal
- Output the
schema.ts
file when runningdrizzle-kit introspect
Usage
driver
- Type:
'aws-data-api' | 'd1-http' | 'expo' | 'turso'
- Commands:
push
,introspect
,migrate
The driver
parameter is responsible for explicitly providing a driver to use when accessing a database
for the introspect and push commands. It is also useful for HTTP-based databases where connecting using
a database connection url is not possible. For example, Turso and Cloudflare D1!
Usage
dbCredentials
- Type:
PostgresCredentials, MySQLCredentials, SQLiteCredentials, TursoCredentials
- Commands:
push
,introspect
Each dialect
should have dbCredentials
field to provide a means of connecting to the database.
PostgresCredentials (postgresql
)
MySQLCredentials (mysql
)
SQLiteCredentials (libsql
, better-sqlite3
)
TursoCredentials (turso
)
D1Credentials (d1
) - WIP
migrations
- Type:
object
- Commands:
migrate
migrations
param let’s use specify custom table and schema(PostgreSQL only) for migrations.
By default, all information about executed migrations will be stored in the database inside the
__drizzle_migrations
table, and for PostgreSQL, inside the drizzle schema.
However, you can configure where to store those records.
Usage
breakpoints
- Type:
boolean
- Default:
true
- Commands:
generate
,introspect
breakpoints
param lets you enable/disable SQL statement breakpoints in generated migrations. It’s optional and true
by default,
it’s necessary to properly apply migrations on databases, that do not support multiple DDL alternation statements in one transaction(MySQL, SQLite)
and Drizzle ORM has to apply them sequentially one by one.
Usage
tablesFilters
- Type:
string | string[]
- Commands:
push
tablesFilter
param lets you filter tables with glob(opens in a new tab) syntax for db push command.
It’s useful when you have only one database avaialable for several separate projects with separate sql schemas.
How to define multi-project tables with Drizzle ORM — see here.
Usage
In this case, only tables that start with project1_
will be synced with the database
schemaFilter
- Type:
string | string[]
- Default:
["public"]
- Commands:
push
,introspect
- Available databases:
PostgreSQL
The schemaFilter
parameter allows you to define which schema in PostgreSQL should be used for either introspect
or push
commands.
This parameter accepts a single schema as a string or an array of schemas as strings. No glob pattern is supported here.
By default, drizzle will use the public
schema for both commands, but you can add any schema you need.
For example, having schemaFilter: ["my_schema"]
will only look for tables in both the database and
drizzle schema that are a part of the my_schema
schema.
Usage
verbose
- Type:
boolean
- Default: false
- Commands:
push
This command is used for drizzle-kit push
commands and prints all statements that will be executed.
Note: This command will only print the statements that should be executed.
To approve them before applying, please refer to the strict
command.
Usage
strict
- Type:
boolean
- Default: false
- Commands:
push
This command is used for drizzle-kit push
commands and will always ask for your confirmation, either
to execute all statements needed to sync your schema with the database or not.
Usage
introspect
- Type:
object
This section is a reference to introspect
object inside drizzle.config.*
file.
casing
- Type:
'preserve' | 'camel'
- Default:
camel
- Commands:
This command is responsible for a strategy for choosing column, table, constraint JS key names while introspecting your databse.
Usage
Example