Documentation
Config Reference

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

import { Config } from "drizzle-kit";
 
export default {
  schema: "./schema.ts",
  out: "./drizzle"
} satisfies Config;

JavaScript example

/** @type { import("drizzle-kit").Config } */
export default {
  schema: "./schema.ts",
  out: "./drizzle"
};

Options

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 (opens in a new tab) or array of globs syntax.

Usage

export default {
  schema: "./schema.ts",
} satisfies Config;

out

  • Type: string | string[]
  • Default: drizzle
  • Commands: generate, check, up, drop, introspect

The out parameter allows you to define the folder for your migrations.

In this folder, drizzle-kit will:

  1. Store migration files, meta, and journal
  2. Output the schema.ts file when running drizzle-kit introspect

Usage

export default {
  out: "./drizzle",
} satisfies Config;

driver

  • Type: 'pg' | 'mysql2' | 'better-sqlite' | 'libsql' | 'turso'
  • Commands: push, introspect
⚠️

Current param is available in drizzle-kit@0.19.0 and higher. In previous versions you should not use this param

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 (opens in a new tab)

Usage

export default {
  driver: "mysql2"
} satisfies Config;

dbCredentials

  • Type: PostgresCredentials, MySQLCredentials, SQLiteCredentials, TursoCredentials
  • Commands: push, introspect
💡

Each driver should have dbCredentials field to provide a means of connecting to the database

PostgresCredentials (pg)

export default {
  dbCredentials: {
    connectionsString: '',
  }
} satisfies Config;

MySQLCredentials (mysql2)

export default {
  dbCredentials: {
    connectionsString: '',
  }
} satisfies Config;

SQLiteCredentials (libsql, better-sqlite3)

export default {
  dbCredentials: {
    url: '',
  }
} satisfies Config;

TursoCredentials

export default {
  dbCredentials: {
    url: '',
    authToken: ''
  }
} satisfies Config;

breakpoints

  • Type: boolean
  • Default: true (starting from drizzle-kit@0.19.0)
  • 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.

CREATE TABLE `book` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`name` text
);
--> statement-breakpoint
CREATE TABLE `book_to_author` (
	`author_id` integer,
	`book_id` integer,
	PRIMARY KEY(`book_id`, `author_id`)
);

Usage

export default {
  breakpoints: true
} satisfies Config;

tableFilters

  • 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

export default {
  tablesFilter: ["project1_*"],
} satisfies Config;

In this case, only tables that start with project1_ will be synced with the database

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

export default {
  verbose: true
} satisfies Config;

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

export default {
  strict: true
} satisfies Config;

introspect

  • Type: object

This section is a reference to introspect object inside drizzle.config.* file

casing

  • Type: 'peserve' | 'camel'
  • Default: camel
  • Commands:

This command is responsible for a strategy for choosing column, table, constraint JS key names while introspecting your databse

Usage

export default {
  introspect: {
    casing: 'preserve'
  }
} satisfies Config;

Example

export const user_preferences = sqliteTable(
  "user_preferences",
  {
    id: integer("id").primaryKey(),
    name: integer("name").notNull(),
    user_id: integer("user_id").notNull(),
  }
);