Become a Gold Sponsor

Drizzle Kit configuration file

This guide assumes familiarity with:

Drizzle Kit lets you declare configuration options in TypeScript or JavaScript configuration files.

๐Ÿ“ฆ <project root>
 โ”œ ...
 โ”œ ๐Ÿ“‚ drizzle
 โ”œ ๐Ÿ“‚ src
 โ”œ ๐Ÿ“œ drizzle.config.ts
 โ”” ๐Ÿ“œ package.json
drizzle.config.ts
drizzle.config.js
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  schema: "./src/schema.ts",
  out: "./drizzle",
});

Example of an extended config file

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  out: "./drizzle",
  dialect: "postgresql",
  schema: "./src/schema.ts",

  driver: "pglite",
  dbCredentials: {
    url: "./database/",
  },

  extensionsFilters: ["postgis"],
  schemaFilter: "public",
  tablesFilter: "*",

  introspect: {
    casing: "camel",
  },

  migrations: {
    prefix: "timestamp",
    table: "__drizzle_migrations__",
    schema: "public",
  },

  breakpoints: true,
  strict: true,
  verbose: true,
});
Expand

Multiple configuration files

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:

npm
yarn
pnpm
bun
npx drizzle-kit generate --config=drizzle-dev.config.ts
npx drizzle-kit generate --config=drizzle-prod.config.ts
๐Ÿ“ฆ <project root>
 โ”œ ๐Ÿ“‚ drizzle
 โ”œ ๐Ÿ“‚ src
 โ”œ ๐Ÿ“œ .env
 โ”œ ๐Ÿ“œ drizzle-dev.config.ts
 โ”œ ๐Ÿ“œ drizzle-prod.config.ts
 โ”œ ๐Ÿ“œ package.json
 โ”” ๐Ÿ“œ tsconfig.json

Migrations folder

out param lets you define folder for your migrations, itโ€™s optional and drizzle by default.
Itโ€™s very useful since you can have many separate schemas for different databases in the same project and have different migration folders for them.

Migration folder contains .sql migration files and _meta folder which is used by drizzle-kit

๐Ÿ“ฆ <project root>
 โ”œ ...
 โ”œ ๐Ÿ“‚ drizzle
 โ”‚ โ”œ ๐Ÿ“‚ _meta
 โ”‚ โ”œ ๐Ÿ“œ user.ts 
 โ”‚ โ”œ ๐Ÿ“œ post.ts 
 โ”‚ โ”” ๐Ÿ“œ comment.ts 
 โ”œ ๐Ÿ“‚ src
 โ”œ ๐Ÿ“œ drizzle.config.ts
 โ”” ๐Ÿ“œ package.json
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql", // "mysql" | "sqlite" | "postgresql"
  schema: "./src/schema/*",
  out: "./drizzle",
});

---

dialect

Dialect of the database youโ€™re using

typepostgresql mysql sqlite turso
defaultโ€”
commandsgenerate migrate push pull check up
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "mysql", 
});

schema

glob based path to drizzle schema file(s) or folder(s) contaning schema files.

typestring string[]
defaultโ€”
commandsgenerate push
Example 1
Example 2
Example 3
Example 4
๐Ÿ“ฆ <project root>
 โ”œ ...
 โ”œ ๐Ÿ“‚ drizzle
 โ”œ ๐Ÿ“‚ src
 โ”‚ โ”œ ...
 โ”‚ โ”œ ๐Ÿ“œ index.ts
 โ”‚ โ”” ๐Ÿ“œ schema.ts 
 โ”œ ๐Ÿ“œ drizzle.config.ts
 โ”” ๐Ÿ“œ package.json
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/schema.ts",
});

out

Defines output folder of your SQL migration files, json snapshots of your schema and schema.ts from drizzle-kit pull command.

typestring string[]
defaultdrizzle
commandsgenerate migrate push pull check up
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  out: "./drizzle", 
});

driver

Drizzle Kit automatically picks available database driver from your current project based on the provided dialect, yet some vendor specific databases require a different subset of connection params.

driver option letโ€™s you explicitely pick those exceptions drivers.

typeaws-data-api d1-http pglight
defaultโ€”
commandsmigrate push pull
AWS Data API
PGLite
Cloudflare D1 HTTP
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  schema: "./src/schema.ts",
  driver: "aws-data-api",
  dbCredentials: {
    database: "database",
    resourceArn: "resourceArn",
    secretArn: "secretArn",
  },
};

---

dbCredentials

Database connection credentials in a form of url, user:password@host:port/db params or exceptions drivers(aws-data-api d1-http pglight ) specific connection options.

typeunion of drivers connection options
defaultโ€”
commandsmigrate push pull
PostgreSQL
MySQL
SQLite
Turso
Cloudflare D1
AWS Data API
PGLite
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
  dialect: "postgresql",
  dbCredentials: {
    url: "postgres://user:password@host:port/db",
  }
})
import { defineConfig } from 'drizzle-kit'

// via connection params
export default defineConfig({
  dialect: "postgresql",
  dbCredentials: {
    host: "host",
    port: 5432,
    user: "user",
    password: "password",
    database: "dbname",
    ssl: true, // can be boolean | "require" | "allow" | "prefer" | "verify-full" | options from node:tls
  }
})

migrations

When running drizzle-kit migrate - drizzle will records about successfully applied migrations in your database in log table named __drizzle_migrations in public schema(PostgreSQL only).

migrations config options lets you change both migrations log table name and schema.

type{ table: string, schema: string }
default{ table: "__drizzle_migrations", schema: "drizzle" }
commandsmigrate
export default defineConfig({
  dialect: "postgresql",
  schema: "./src/schema.ts",
  migrations: {
    table: 'my-migrations-table', // `__drizzle_migrations` by default
    schema: 'public', // used in PostgreSQL only, `drizzle` by default
  },
});

introspect

Cofiguration for drizzle-kit pull command.

casing is responsible for in-code column keys casing

type{ casing: "preserve" | "camel" }
default{ casing: "camel" }
commandspull
camel
preserve
import * as p from "drizzle-orm/pg-core"

export const users = p.pgTable("users", {
  id: p.serial(),
  firstName: p.text("first-name"),
  lastName: p.text("LastName"),
  email: p.text(),
  phoneNumber: p.text("phone_number"),
});
SELECT a.attname AS column_name, format_type(a.atttypid, a.atttypmod) as data_type FROM pg_catalog.pg_attribute a;
 column_name   | data_type        
---------------+------------------------
 id            | serial
 first-name    | text
 LastName      | text
 email         | text
 phone_number  | text

---

tablesFilter

If you want to run multiple projects with one database - check out our guide.

drizzle-kit push and drizzle-kit pull will by default manage all tables in public schema. You can configure list of tables, schemas and extensions via tablesFilters, schemaFilter and extensionFilters options.

tablesFilter option lets you specify glob based table names filter, e.g. ["users", "user_info"] or "user*"

typestring string[]
defaultโ€”
commandsgenerate push pull
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  tablesFilter: ["users", "posts", "project1_*"],
});

schemaFilter

If you want to run multiple projects with one database - check out our guide.

drizzle-kit push and drizzle-kit pull will by default manage all tables in public schema. You can configure list of tables, schemas and extensions via tablesFilters, schemaFilter and extensionFilters options.

schemaFilter option lets you specify list of schemas for Drizzle Kit to manage

typestring[]
default["public"]
commandsgenerate push pull
export default defineConfig({
  dialect: "postgresql",
  schemaFilter: ["public", "schema1", "schema2"],
});

extensionsFilters

Some extensions like postgis, when installed on the database, create its own tables in public schema. Those tables have to be ignored by drizzle-kit push or drizzle-kit pull.

extensionsFilters option lets you declare list of installed extensions for drizzle kit to ignore their tables in the schema.

type["postgis"]
default[]
commandspush pull
export default defineConfig({
  dialect: "postgresql",
  extensionsFilters: ["postgis"],
});

---

strict

Prompts confirmation to run printed SQL statements when running drizzle-kit push command.

typeboolean
defaultfalse
commandspush
export default defineConfig({
  dialect: "postgresql",
  breakpoints: false,
});

verbose

Print all SQL statements during drizzle-kit push command.

typeboolean
defaulttrue
commandsgenerate pull
export default defineConfig({
  dialect: "postgresql",
  breakpoints: false,
});

breakpoints

Drizzle Kit will automatically embed --> statement-breakpoint into generated SQL migration files, thatโ€™s necessary for databases that do not support multiple DDL alternation statements in one transaction(MySQL and SQLite).

breakpoints option flag lets you switch it on and off

typeboolean
defaulttrue
commandsgenerate pull
export default defineConfig({
  dialect: "postgresql",
  breakpoints: false,
});