Configuration files

Drizzle Kit lets you declare configurations in TypeScript, JavaScript or JSON configuration files.

You can have autocomplete experience and a very convenient environment variables flow!

πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ drizzle
 β”œ πŸ“‚ src
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
drizzle.config.ts
drizzle.config.js
drizzle.config.json
import type { Config } from "drizzle-kit";

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

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

Schema files paths

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.

Example 1
Example 2
Example 3
πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ drizzle
 β”œ πŸ“‚ src
 β”‚ β”œ ...
 β”‚ β”œ πŸ“œ index.ts
 β”‚ β”” πŸ“œ schema.ts 
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
import type { Config } from "drizzle-kit";

export default {
  schema: "./src/schema.ts",
} satisfies Config;
πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ drizzle
 β”œ πŸ“‚ src
 β”‚ β”œ πŸ“‚ user
 β”‚ β”‚ β”œ πŸ“œ handler.ts 
 β”‚ β”‚ β”” πŸ“œ schema.ts 
 β”‚ β”œ πŸ“‚ posts
 β”‚ β”‚ β”œ πŸ“œ handler.ts 
 β”‚ β”‚ β”” πŸ“œ schema.ts 
 β”‚ β”” πŸ“œ index.ts
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
import type { Config } from "drizzle-kit";

export default {
  schema: "./src/**/schema.ts",
  //or
  schema: ["./src/user/schema.ts", "./src/posts/schema.ts"]
} satisfies Config;
πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ drizzle
 β”œ πŸ“‚ src
 β”‚ β”œ πŸ“‚ schema
 β”‚ β”‚ β”œ πŸ“œ user.ts 
 β”‚ β”‚ β”œ πŸ“œ post.ts 
 β”‚ β”‚ β”” πŸ“œ comment.ts 
 β”‚ β”” πŸ“œ index.ts
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
import type { Config } from "drizzle-kit";

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

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

⚠️

Don’t delete any files manually, please refer to drizzle-kit drop command

πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ drizzle
 β”‚ β”œ πŸ“‚ _meta
 β”‚ β”œ πŸ“œ user.ts 
 β”‚ β”œ πŸ“œ post.ts 
 β”‚ β”” πŸ“œ comment.ts 
 β”œ πŸ“‚ src
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
import type { Config } from "drizzle-kit";

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

SQL breakpoints

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`)
);

Push and Pull

Drizzle Kit provides you introspect and push APIs.

We mirror connection params of database drivers.

Connection URI
Connection params
import type { Config } from "drizzle-kit";

export default {
  schema: "./src/schema/*",
  out: "./drizzle",
  driver: 'pg',
  dbCredentials: {
    connectionString: process.env.DB_URL,
  }
} satisfies Config;
ℹ️

When using the PlanetScale driver, your connection string must end with ?ssl={"rejectUnauthorized":true} instead of ?sslaccept=strict.

import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config();

export default {
  schema: "./src/schema/*",
  out: "./drizzle",
  driver: 'pg',
  dbCredentials: {
    user: "postgres",
    password: process.env.DATABASE_PASSWORD,
    host: "127.0.0.1",
    port: 5432,
    database: "db",
  }
} satisfies Config;

Multi-project schema

tablesFilter param lets you filter tables with glob syntax for db push command. It’s useful when you have only one database available for several separate projects with separate sql schemas.

How to define multi-project tables with Drizzle ORM β€” see here.

import { serial, text, pgTableCreator } from 'drizzle-orm/pg-core';

const pgTable = pgTableCreator((name) => `project1_${name}`);

const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
});
import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
dotenv.config();

export default {
  schema: "./src/schema/*",
  out: "./drizzle",
  driver: "mysql2",
  dbCredentials: {
    uri: process.env.DATABASE_URL,
  }
  tablesFilter: ["project1_*"],
} satisfies Config;

You can apply multiple or filters:

tablesFilter: ["project1_*", "project2_*"]