drizzle-kit
0.31.11 · 21 Sep 2026MIT42.7M / weekRepositoryHomepagenpmAtom feed
187 stable releases, newest first, by release line. Notes are quoted as the maintainers published them.
- 0.31.x · latest line
0.31.11
21 Sep 2026Warn about silent migration skips on drizzle-kit checks
0.31.10
17 Mar 2026Updated to
hanji@0.0.8- native bunstringWidth,stripANSIsupport, errors for non-TTY environmentsWe've migrated away from
esbuild-registertotsxloader, it will now allow to usedrizzle-kitseamlessly with bothESMandCJSmodulesWe've also added native
BunandDenolaunch support, which will not triggertsxloader and utilise nativebunanddenoimports capabilities and faster startup times
0.31.9
9 Feb 2026drizzle-kit api improvements for D1 connections
0.31.8
4 Dec 2025Fixed external dependencies in build configuration.
Bug fixes
Fixed external dependencies in build configuration.
0.31.5
26 Sep 2025Add casing support to studio configuration and related functions
0.31.4
27 Jun 2025Fixed
halfvec,bitandsparsevectype generation bug in drizzle-kit
0.31.3
26 Jun 2025Internal changes to Studio context. Added
databaseNameandpackageNameproperties for Studio
0.31.2
23 Jun 2025Fixed relations extraction to not interfere with Drizzle Studio.
0.31.1
3 May 2025Enable extensions schemas in
drizzle.config.tsRun
drizzle-kit pullDone!
Fixed
drizzle-kit pullbugs when using Gel extensions.Because Gel extensions create schema names containing
::(for example,ext::auth), Drizzle previously handled these names incorrectly. Starting with this release, you can use Gel extensions without any problems. Here’s what you should do:Enable extensions schemas in
drizzle.config.ts
import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: 'gel', schemaFilter: ['ext::auth', 'public'] });Run
drizzle-kit pullDone!
0.31.0
15 Apr 2025Change the column data types from the enum to text
Drop the old enum
Features and improvements
Enum DDL improvements
For situations where you drop an
enumvalue or reorder values in anenum, there is no native way to do this in PostgreSQL. To handle these cases,drizzle-kitused to:Change the column data types from the enum to text
Drop the old enum
Add the new enum
Change the column data types back to the new enum
However, there were a few scenarios that weren’t covered:
PostgreSQLwasn’t updating default expressions for columns when their data types changedTherefore, for cases where you either change a column’s data type from an
enumto some other type, drop anenumvalue, or reorderenumvalues, we now do the following:Change the column data types from the enum to text
Set the default using the ::text expression
Drop the old enum
Add the new enum
Change the column data types back to the new enum
Set the default using the ::<new_enum> expression
esbuildversion upgradeFor
drizzle-kitwe upgraded the version to latest (0.25.2), thanks @paulmarsicloudBug fixes
- 0.30.x
0.30.5
25 Feb 2025Use the
gelCLI to manage your schema.Use the
gelCLI to generate and apply migrations to the database.Use drizzle-kit to pull the Gel database schema into a Drizzle schema.
New Features
Added
Geldialect support andgel-jsclient supportDrizzle is getting a new
Geldialect with its own types and Gel-specific logic. In this first iteration, almost all query-building features have been copied from thePostgreSQLdialect since Gel is fully PostgreSQL-compatible. The only change in this iteration is the data types. The Gel dialect has a different set of available data types, and all mappings for these types have been designed to avoid any extra conversions on Drizzle's side. This means you will insert and select exactly the same data as supported by the Gel protocol.Drizzle + Gel integration will work only through
drizzle-kit pull. Drizzle won't supportgenerate,migrate, orpushfeatures in this case. Instead, drizzle-kit is used solely to pull the Drizzle schema from the Gel database, which can then be used in yourdrizzle-ormqueries.The Gel + Drizzle workflow:
Use the
gelCLI to manage your schema.Use the
gelCLI to generate and apply migrations to the database.Use drizzle-kit to pull the Gel database schema into a Drizzle schema.
Use drizzle-orm with gel-js to query the Gel database.
On the drizzle-kit side you can now use
dialect: "gel"// drizzle.config.ts import { defineConfig } from 'drizzle-kit'; export default defineConfig({ dialect: 'gel', });For a complete Get Started tutorial you can use our new guides:
0.30.4
29 Jan 2025Fix bug that generates incorrect syntax when introspect in mysql
Fix a bug that caused incorrect syntax output when introspect in unsigned columns
0.30.3
27 Jan 2025SingleStore
pushandgenerateimprovementsAs SingleStore did not support certain DDL statements before this release, you might encounter an error indicating that some schema changes cannot be applied due to a database issue. Starting from this version, drizzle-kit will detect such cases and initiate table recreation with data transfer between the tables
Bug fixes
0.30.2
16 Jan 2025Fix certificates generation utility for Drizzle Studio; [BUG]: [drizzle-kit]: drizzle-kit dependency on drizzle-studio perms error
0.30.1
13 Dec 2024To make drizzle-kit integration with other migration tools, like Atlas much easier, we've prepared a new command called
export. It will translate your drizzle schema in SQL representation(DDL) statements and outputs to the consoleNew Features
drizzle-kit exportTo make drizzle-kit integration with other migration tools, like Atlas much easier, we've prepared a new command called
export. It will translate your drizzle schema in SQL representation(DDL) statements and outputs to the console// schema.ts import { pgTable, serial, text } from 'drizzle-orm/pg-core' export const users = pgTable('users', { id: serial('id').primaryKey(), email: text('email').notNull(), name: text('name') });Running
npx drizzle-kit export
will output this string to console
CREATE TABLE "users" ( "id" serial PRIMARY KEY NOT NULL, "email" text NOT NULL, "name" text );By default, the only option for now is
--sql, so the output format will be SQL DDL statements. In the future, we will support additional output formats to accommodate more migration toolsnpx drizzle-kit export --sql
0.30.0
9 Dec 2024An updated and improved migration workflow featuring commutative migrations, a revised folder structure, and enhanced collaboration capabilities for migrations.
Better support for Xata migrations.
Compatibility with CockroachDB (achieving full compatibility will only require removing serial fields from the migration folder).
Starting from this update, the PostgreSQL dialect will align with the behavior of all other dialects. It will no longer include
IF NOT EXISTS,$DO, or similar statements, which could cause incorrect DDL statements to not fail when an object already exists in the database and should actually fail.This change marks our first step toward several major upgrades we are preparing:
An updated and improved migration workflow featuring commutative migrations, a revised folder structure, and enhanced collaboration capabilities for migrations.
Better support for Xata migrations.
Compatibility with CockroachDB (achieving full compatibility will only require removing serial fields from the migration folder).
- 0.29.x
0.29.1
4 Dec 2024Fix SingleStore generate migrations command
0.29.0
3 Dec 2024Thanks to the SingleStore team for creating a PR with all the necessary changes to support the MySQL-compatible part of SingleStore. You can already start using it with Drizzle. The SingleStore team will also help us iterate through updates and make more SingleStore-specific features available in Drizzle
New Dialects
SingleStoredialect is now available in DrizzleThanks to the SingleStore team for creating a PR with all the necessary changes to support the MySQL-compatible part of SingleStore. You can already start using it with Drizzle. The SingleStore team will also help us iterate through updates and make more SingleStore-specific features available in Drizzle
import 'dotenv/config'; import { defineConfig } from 'drizzle-kit'; export default defineConfig({ dialect: 'singlestore', out: './drizzle', schema: './src/db/schema.ts', dbCredentials: { url: process.env.DATABASE_URL!, }, });You can check out our Getting started guides to try SingleStore!
New Drivers
SQLite Durable Objectsdriver is now available in DrizzleYou can now query SQLite Durable Objects in Drizzle!
For the full example, please check our Get Started Section
import 'dotenv/config'; import { defineConfig } from 'drizzle-kit'; export default defineConfig({ out: './drizzle', schema: './src/db/schema.ts', dialect: 'sqlite', driver: 'durable-sqlite', });- 0.28.x
0.28.0
6 Nov 2024Added an OHM static imports checker to identify unexpected imports within a chain of imports in the drizzle-kit repo. For example, it checks if drizzle-orm is imported before drizzle-kit and verifies if the drizzle-orm import is available in your project.
Improvements
Added an OHM static imports checker to identify unexpected imports within a chain of imports in the drizzle-kit repo. For example, it checks if drizzle-orm is imported before drizzle-kit and verifies if the drizzle-orm import is available in your project.
Bug Fixes
[BUG]: [drizzle-kit]: Fix breakpoints option cannot be disabled
[BUG]: drizzle-kit introspect: SMALLINT import missing and incorrect DECIMAL UNSIGNED handling
[BUG]: Can't parse float(8,2) from database (precision and scale and/or unsigned breaks float types)
[BUG]: PgEnum generated migration doesn't escape single quotes
[BUG]: Time with precision in drizzle-orm/pg-core adds double-quotes around type
[BUG]: TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
[BUG]: drizzle-kit introspect generates CURRENT_TIMESTAMP without sql operator on date column
[BUG]: Drizzle-kit introspect doesn't pull correct defautl statement
[BUG]: Problem on MacBook - This statement does not return data. Use run() instead
[BUG]: Enum column names that are used as arrays are not quoted
[BUG]: drizzle-kit does not respect the order of columns configured in primaryKey()
- 0.27.x
0.27.2
6 Nov 2024Fix TypeError: Cannot read properties of undefined (reading 'isRLSEnabled')
Fix push bugs, when pushing a schema with linked policy to a table from
drizzle-orm/supabase
0.27.0
30 Oct 2024This version of
drizzle-jitrequiresdrizzle-orm@0.36.0to enable all new featuresNew Features
Row-Level Security (RLS)
With Drizzle, you can enable Row-Level Security (RLS) for any Postgres table, create policies with various options, and define and manage the roles those policies apply to.
Drizzle supports a raw representation of Postgres policies and roles that can be used in any way you want. This works with popular Postgres database providers such as
NeonandSupabase.In Drizzle, we have specific predefined RLS roles and functions for RLS with both database providers, but you can also define your own logic.
Enable RLS
If you just want to enable RLS on a table without adding policies, you can use
.enableRLS()As mentioned in the PostgreSQL documentation:
If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified.
Operations that apply to the whole table, such as TRUNCATE and REFERENCES, are not subject to row security.import { integer, pgTable } from 'drizzle-orm/pg-core'; export const users = pgTable('users', { id: integer(), }).enableRLS();If you add a policy to a table, RLS will be enabled automatically. So, there’s no need to explicitly enable RLS when adding policies to a table.
Roles
Currently, Drizzle supports defining roles with a few different options, as shown below. Support for more options will be added in a future release.
import { pgRole } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin', { createRole: true, createDb: true, inherit: true });If a role already exists in your database, and you don’t want drizzle-kit to ‘see’ it or include it in migrations, you can mark the role as existing.
import { pgRole } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin').existing();Policies
To fully leverage RLS, you can define policies within a Drizzle table.
In PostgreSQL, policies should be linked to an existing table. Since policies are always associated with a specific table, we decided that policy definitions should be defined as a parameter of
pgTableExample of pgPolicy with all available properties
import { sql } from 'drizzle-orm'; import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin'); export const users = pgTable('users', { id: integer(), }, (t) => [ pgPolicy('policy', { as: 'permissive', to: admin, for: 'delete', using: sql``, withCheck: sql``, }), ]);Link Policy to an existing table
There are situations where you need to link a policy to an existing table in your database.
The most common use case is with database providers likeNeonorSupabase, where you need to add a policy
to their existing tables. In this case, you can use the.link()APIimport { sql } from "drizzle-orm"; import { pgPolicy } from "drizzle-orm/pg-core"; import { authenticatedRole, realtimeMessages } from "drizzle-orm/supabase"; export const policy = pgPolicy("authenticated role insert policy", { for: "insert", to: authenticatedRole, using: sql``, }).link(realtimeMessages);Migrations
If you are using drizzle-kit to manage your schema and roles, there may be situations where you want to refer to roles that are not defined in your Drizzle schema. In such cases, you may want drizzle-kit to skip managing these roles without having to define each role in your drizzle schema and marking it with
.existing().In these cases, you can use
entities.rolesindrizzle.config.ts. For a complete reference, refer to the thedrizzle.config.tsdocumentation.By default,
drizzle-kitdoes not manage roles for you, so you will need to enable this feature indrizzle.config.ts.// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: 'postgresql', schema: "./drizzle/schema.ts", dbCredentials: { url: process.env.DATABASE_URL! }, verbose: true, strict: true, entities: { roles: true } });In case you need additional configuration options, let's take a look at a few more examples.
You have an
adminrole and want to exclude it from the list of manageable roles// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ ... entities: { roles: { exclude: ['admin'] } } });You have an
adminrole and want to include it in the list of manageable roles// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ ... entities: { roles: { include: ['admin'] } } });If you are using
Neonand want to exclude Neon-defined roles, you can use the provider option// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ ... entities: { roles: { provider: 'neon' } } });If you are using
Supabaseand want to exclude Supabase-defined roles, you can use the provider option// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ ... entities: { roles: { provider: 'supabase' } } });You may encounter situations where Drizzle is slightly outdated compared to new roles specified by your database provider.
In such cases, you can use theprovideroption andexcludeadditional roles:// drizzle.config.ts import { defineConfig } from "drizzle-kit"; export default defineConfig({ ... entities: { roles: { provider: 'supabase', exclude: ['new_supabase_role'] } } });RLS on views
With Drizzle, you can also specify RLS policies on views. For this, you need to use
security_invokerin the view's WITH options. Here is a small example:... export const roomsUsersProfiles = pgView("rooms_users_profiles") .with({ securityInvoker: true, }) .as((qb) => qb .select({ ...getTableColumns(roomsUsers), email: profiles.email, }) .from(roomsUsers) .innerJoin(profiles, eq(roomsUsers.userId, profiles.id)) );Using with Neon
The Neon Team helped us implement their vision of a wrapper on top of our raw policies API. We defined a specific
/neonimport with thecrudPolicyfunction that includes predefined functions and Neon's default roles.Here's an example of how to use the
crudPolicyfunction:import { crudPolicy } from 'drizzle-orm/neon'; import { integer, pgRole, pgTable } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin'); export const users = pgTable('users', { id: integer(), }, (t) => [ crudPolicy({ role: admin, read: true, modify: false }), ]);This policy is equivalent to:
import { sql } from 'drizzle-orm'; import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin'); export const users = pgTable('users', { id: integer(), }, (t) => [ pgPolicy(`crud-${admin.name}-policy-insert`, { for: 'insert', to: admin, withCheck: sql`false`, }), pgPolicy(`crud-${admin.name}-policy-update`, { for: 'update', to: admin, using: sql`false`, withCheck: sql`false`, }), pgPolicy(`crud-${admin.name}-policy-delete`, { for: 'delete', to: admin, using: sql`false`, }), pgPolicy(`crud-${admin.name}-policy-select`, { for: 'select', to: admin, using: sql`true`, }), ]);Neonexposes predefinedauthenticatedandanaonymousroles and related functions. If you are usingNeonfor RLS, you can use these roles, which are marked as existing, and the related functions in your RLS queries.// drizzle-orm/neon export const authenticatedRole = pgRole('authenticated').existing(); export const anonymousRole = pgRole('anonymous').existing(); export const authUid = (userIdColumn: AnyPgColumn) => sql`(select auth.user_id() = ${userIdColumn})`;For example, you can use the
Neonpredefined roles and functions like this:import { sql } from 'drizzle-orm'; import { authenticatedRole } from 'drizzle-orm/neon'; import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin'); export const users = pgTable('users', { id: integer(), }, (t) => [ pgPolicy(`policy-insert`, { for: 'insert', to: authenticatedRole, withCheck: sql`false`, }), ]);Using with Supabase
We also have a
/supabaseimport with a set of predefined roles marked as existing, which you can use in your schema.
This import will be extended in a future release with more functions and helpers to make using RLS andSupabasesimpler.// drizzle-orm/supabase export const anonRole = pgRole('anon').existing(); export const authenticatedRole = pgRole('authenticated').existing(); export const serviceRole = pgRole('service_role').existing(); export const postgresRole = pgRole('postgres_role').existing(); export const supabaseAuthAdminRole = pgRole('supabase_auth_admin').existing();For example, you can use the
Supabasepredefined roles like this:import { sql } from 'drizzle-orm'; import { serviceRole } from 'drizzle-orm/supabase'; import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core'; export const admin = pgRole('admin'); export const users = pgTable('users', { id: integer(), }, (t) => [ pgPolicy(`policy-insert`, { for: 'insert', to: serviceRole, withCheck: sql`false`, }), ]);The
/supabaseimport also includes predefined tables and functions that you can use in your application// drizzle-orm/supabase const auth = pgSchema('auth'); export const authUsers = auth.table('users', { id: uuid().primaryKey().notNull(), }); const realtime = pgSchema('realtime'); export const realtimeMessages = realtime.table( 'messages', { id: bigserial({ mode: 'bigint' }).primaryKey(), topic: text().notNull(), extension: text({ enum: ['presence', 'broadcast', 'postgres_changes'], }).notNull(), }, ); export const authUid = sql`(select auth.uid())`; export const realtimeTopic = sql`realtime.topic()`;This allows you to use it in your code, and Drizzle Kit will treat them as existing databases,
using them only as information to connect to other entitiesimport { foreignKey, pgPolicy, pgTable, text, uuid } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm/sql"; import { authenticatedRole, authUsers } from "drizzle-orm/supabase"; export const profiles = pgTable( "profiles", { id: uuid().primaryKey().notNull(), email: text().notNull(), }, (table) => [ foreignKey({ columns: [table.id], // reference to the auth table from Supabase foreignColumns: [authUsers.id], name: "profiles_id_fk", }).onDelete("cascade"), pgPolicy("authenticated can view all profiles", { for: "select", // using predefined role from Supabase to: authenticatedRole, using: sql`true`, }), ] );Let's check an example of adding a policy to a table that exists in
Supabaseimport { sql } from "drizzle-orm"; import { pgPolicy } from "drizzle-orm/pg-core"; import { authenticatedRole, realtimeMessages } from "drizzle-orm/supabase"; export const policy = pgPolicy("authenticated role insert policy", { for: "insert", to: authenticatedRole, using: sql``, }).link(realtimeMessages);Bug fixes
- 0.26.x
0.26.2
16 Oct 2024Updated internal versions for the drizzle-kit and drizzle-orm packages. Changes were introduced in the last minor release, and you are required to upgrade both packages to ensure they work as expected
0.26.1
15 Oct 2024Fix
data is malformedfor views
0.26.0
15 Oct 2024generatewill work as expected for all check constraint changes.pushwill detect only check renames and will recreate the constraint. All other changes to SQL won't be detected and will be ignored.generatewill work as expected for all view changes
While writing this update, we found one bug that may occur with views in MySQL and SQLite, so please use the
drizzle-kit@0.26.1releaseNew Features
Checks support in
drizzle-kitYou can use drizzle-kit to manage your
checkconstraint defined in drizzle-orm schema definitionFor example current drizzle table:
import { sql } from "drizzle-orm"; import { check, pgTable } from "drizzle-orm/pg-core"; export const users = pgTable( "users", (c) => ({ id: c.uuid().defaultRandom().primaryKey(), username: c.text().notNull(), age: c.integer(), }), (table) => ({ checkConstraint: check("age_check", sql`${table.age} > 21`), }) );will be generated into
CREATE TABLE IF NOT EXISTS "users" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "username" text NOT NULL, "age" integer, CONSTRAINT "age_check" CHECK ("users"."age" > 21) );The same is supported in all dialects
Limitations
generatewill work as expected for all check constraint changes.pushwill detect only check renames and will recreate the constraint. All other changes to SQL won't be detected and will be ignored.
So, if you want to change the constraint's SQL definition using only
push, you would need to manually comment out the constraint,push, then put it back with the new SQL definition andpushone more time.Views support in
drizzle-kitYou can use drizzle-kit to manage your
viewsdefined in drizzle-orm schema definition. It will work with all existing dialects and view optionsPostgreSQL
For example current drizzle table:
import { sql } from "drizzle-orm"; import { check, pgMaterializedView, pgTable, pgView, } from "drizzle-orm/pg-core"; export const users = pgTable( "users", (c) => ({ id: c.uuid().defaultRandom().primaryKey(), username: c.text().notNull(), age: c.integer(), }), (table) => ({ checkConstraint: check("age_check", sql`${table.age} > 21`), }) ); export const simpleView = pgView("simple_users_view").as((qb) => qb.select().from(users) ); export const materializedView = pgMaterializedView( "materialized_users_view" ).as((qb) => qb.select().from(users));will be generated into
CREATE TABLE IF NOT EXISTS "users" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "username" text NOT NULL, "age" integer, CONSTRAINT "age_check" CHECK ("users"."age" > 21) ); CREATE VIEW "public"."simple_users_view" AS (select "id", "username", "age" from "users"); CREATE MATERIALIZED VIEW "public"."materialized_users_view" AS (select "id", "username", "age" from "users");Views supported in all dialects, but materialized views are supported only in PostgreSQL
Limitations
generatewill work as expected for all view changespushlimitations:
If you want to change the view's SQL definition using only
push, you would need to manually comment out the view,push, then put it back with the new SQL definition andpushone more time.
Updates for PostgreSQL enums behavior
We've updated enum behavior in Drizzle with PostgreSQL:
Add value after or before in enum: With this change, Drizzle will now respect the order of values in the enum and allow adding new values after or before a specific one.
Support for dropping a value from an enum: In this case, Drizzle will attempt to alter all columns using the enum to text, then drop the existing enum and create a new one with the updated set of values. After that, all columns previously using the enum will be altered back to the new enum.
If the deleted enum value was used by a column, this process will result in a database error.
Support for dropping an enum
Support for moving enums between schemas
Support for renaming enums
- 0.25.x
0.25.0
7 Oct 2024- Breaking
This version of drizzle-orm will only work with
@libsql/client@0.10.0or higher if you are using themigratefunction. For other use cases, you can continue using previous versions(But the suggestion is to upgrade)
To install the latest version, use the command: - Breaking
Previously, we had a common
drizzle.configfor SQLite and Turso users, which allowed a shared strategy for both dialects. Starting with this release, we are introducing the turso dialect in drizzle-kit. We will evolve and improve Turso as a separate dialect with its own migration strategies. Change Data Type: Set a new data type for existing columns.
Breaking changes and migrate guide for Turso users
If you are using Turso and libsql, you will need to upgrade your
drizzle.configand@libsql/clientpackage.- Breaking
This version of drizzle-orm will only work with
@libsql/client@0.10.0or higher if you are using themigratefunction. For other use cases, you can continue using previous versions(But the suggestion is to upgrade)
To install the latest version, use the command:
npm i @libsql/client@latest
- Breaking
Previously, we had a common
drizzle.configfor SQLite and Turso users, which allowed a shared strategy for both dialects. Starting with this release, we are introducing the turso dialect in drizzle-kit. We will evolve and improve Turso as a separate dialect with its own migration strategies.
Before
import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "sqlite", schema: "./schema.ts", out: "./drizzle", dbCredentials: { url: "database.db", }, breakpoints: true, verbose: true, strict: true, });After
import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "turso", schema: "./schema.ts", out: "./drizzle", dbCredentials: { url: "database.db", }, breakpoints: true, verbose: true, strict: true, });If you are using only SQLite, you can use
dialect: "sqlite"LibSQL/Turso and Sqlite migration updates
SQLite "generate" and "push" statements updates
Starting from this release, we will no longer generate comments like this:
'/*\n SQLite does not support "Changing existing column type" out of the box, we do not generate automatic migration for that, so it has to be done manually' + '\n Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php' + '\n https://www.sqlite.org/lang_altertable.html' + '\n https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3' + "\n\n Due to that we don't generate migration automatically and it has to be done manually" + '\n*/'We will generate a set of statements, and you can decide if it's appropriate to create data-moving statements instead. Here is an example of the SQL file you'll receive now:
PRAGMA foreign_keys=OFF; --> statement-breakpoint CREATE TABLE `__new_worker` ( `id` integer PRIMARY KEY NOT NULL, `name` text NOT NULL, `salary` text NOT NULL, `job_id` integer, FOREIGN KEY (`job_id`) REFERENCES `job`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint INSERT INTO `__new_worker`("id", "name", "salary", "job_id") SELECT "id", "name", "salary", "job_id" FROM `worker`; --> statement-breakpoint DROP TABLE `worker`; --> statement-breakpoint ALTER TABLE `__new_worker` RENAME TO `worker`; --> statement-breakpoint PRAGMA foreign_keys=ON;LibSQL/Turso "generate" and "push" statements updates
Since LibSQL supports more ALTER statements than SQLite, we can generate more statements without recreating your schema and moving all the data, which can be potentially dangerous for production environments.
LibSQL and Turso will now have a separate dialect in the Drizzle config file, meaning that we will evolve Turso and LibSQL independently from SQLite and will aim to support as many features as Turso/LibSQL offer.
With the updated LibSQL migration strategy, you will have the ability to:
Change Data Type: Set a new data type for existing columns.
Set and Drop Default Values: Add or remove default values for existing columns.
Set and Drop NOT NULL: Add or remove the NOT NULL constraint on existing columns.
Add References to Existing Columns: Add foreign key references to existing columns
You can find more information in the LibSQL documentation
LIMITATIONS
Dropping foreign key will cause table recreation.
This is because LibSQL/Turso does not support dropping this type of foreign key.
CREATE TABLE `users` ( `id` integer NOT NULL, `name` integer, `age` integer PRIMARY KEY NOT NULL FOREIGN KEY (`name`) REFERENCES `users1`("id") ON UPDATE no action ON DELETE no action );If the table has indexes, altering columns will cause index recreation:
Drizzle-Kit will drop the indexes, modify the columns, and then create the indexes.Adding or dropping composite foreign keys is not supported and will cause table recreation.
Primary key columns can not be altered and will cause table recreation.
Altering columns that are part of foreign key will cause table recreation.
NOTES
You can create a reference on any column type, but if you want to insert values, the referenced column must have a unique index or primary key.
CREATE TABLE parent(a PRIMARY KEY, b UNIQUE, c, d, e, f); CREATE UNIQUE INDEX i1 ON parent(c, d); CREATE INDEX i2 ON parent(e); CREATE UNIQUE INDEX i3 ON parent(f COLLATE nocase); CREATE TABLE child1(f, g REFERENCES parent(a)); -- Ok CREATE TABLE child2(h, i REFERENCES parent(b)); -- Ok CREATE TABLE child3(j, k, FOREIGN KEY(j, k) REFERENCES parent(c, d)); -- Ok CREATE TABLE child4(l, m REFERENCES parent(e)); -- Error! CREATE TABLE child5(n, o REFERENCES parent(f)); -- Error! CREATE TABLE child6(p, q, FOREIGN KEY(p, q) REFERENCES parent(b, c)); -- Error! CREATE TABLE child7(r REFERENCES parent(c)); -- Error!
NOTE: The foreign key for the table child5 is an error because, although the parent key column has a unique index, the index uses a different collating sequence.
See more: sqlite.org/foreignkeys.html
New
casingparam indrizzle-ormanddrizzle-kitThere are more improvements you can make to your schema definition. The most common way to name your variables in a database and in TypeScript code is usually
snake_casein the database andcamelCasein the code. For this case, in Drizzle, you can now define a naming strategy in your database to help Drizzle map column keys automatically. Let's take a table from the previous example and make it work with the new casing API in DrizzleTable can now become:
import { pgTable } from "drizzle-orm/pg-core"; export const ingredients = pgTable("ingredients", (t) => ({ id: t.uuid().defaultRandom().primaryKey(), name: t.text().notNull(), description: t.text(), inStock: t.boolean().default(true), }));As you can see,
inStockdoesn't have a database name alias, but by defining the casing configuration at the connection level, all queries will automatically map it tosnake_caseconst db = await drizzle('node-postgres', { connection: '', casing: 'snake_case' })For
drizzle-kitmigrations generation you should also specifycasingparam in drizzle config, so you can be sure you casing strategy will be applied to drizzle-kit as wellimport { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "postgresql", schema: "./schema.ts", dbCredentials: { url: "postgresql://postgres:password@localhost:5432/db", }, casing: "snake_case", });- 0.24.x
0.24.2
26 Aug 2024mysql-kit: Fix GENERATED ALWAYS AS ... NOT NULL - #2824
New Features
Support for
pglitedriverYou can now use pglite with all drizzle-kit commands, including Drizzle Studio!
import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "postgresql", driver: "pglite", schema: "./schema.ts", dbCredentials: { url: "local-pg.db", }, verbose: true, strict: true, });Bug fixes
mysql-kit: Fix GENERATED ALWAYS AS ... NOT NULL - #2824
0.24.1
22 Aug 2024The Drizzle Kit CLI was not working properly for the
introspectcommand.Added the ability to use column names with special characters for all dialects.
Included PostgreSQL sequences in the introspection process.
Bug fixes
Big thanks to @L-Mario564 for his PR. It conflicted in most cases with a PR that was merged, but we incorporated some of his logic. Merging it would have caused more problems and taken more time to resolve, so we just took a few things from his PR, like removing "::<type>" mappings in introspect and some array type default handlers
What was fixed
The Drizzle Kit CLI was not working properly for the
introspectcommand.Added the ability to use column names with special characters for all dialects.
Included PostgreSQL sequences in the introspection process.
Reworked array type introspection and added all test cases.
Fixed all (we hope) default issues in PostgreSQL, where
::<type>was included in the introspected output.preservecasing option was broken
Tickets that were closed
[BUG]: invalid schema generation with drizzle-kit introspect:pg
[BUG][mysql introspection]: TS error when introspect column including colon
[BUG]: drizzle-kit instrospect command generates syntax error on varchar column types
[BUG]: Introspecting varchar type produces syntactically invalid schema.ts
[BUG]: drizzle-kit introspect casing "preserve" config not working
[BUG]: drizzle-kit introspect fails on required param that is defined
[BUG]: Error when running npx drizzle-kit introspect: "Expected object, received string"
[BUG]: Missing index names when running introspect command [MYSQL]
[BUG]: drizzle-kit introspect TypeError: Cannot read properties of undefined (reading 'toLowerCase')
[BUG]: Incorrect Schema Generated when introspecting extisting pg database
[⚠️🐞BUG]: index() missing argument after introspection, causes tsc error that fails the build
0.24.0
8 Aug 2024If you are using
push, you MAY be prompted to update your table with a new order of columns in the composite primary key. You will need to either change it manually in the database or push the changes, but this may lead to data loss, etc.If you are using
generate, you MAY also be prompted to update your table with a new order of columns in the composite primary key. You can either keep that migration or skip it by emptying the SQL migration file.
Breaking changes (for SQLite users)
Fixed Composite primary key order is not consistent by removing
sortin SQLite and to be consistent with the same logic in PostgreSQL and MySQLThe issue that may arise for SQLite users with any driver using composite primary keys is that the order in the database may differ from the Drizzle schema.
If you are using
push, you MAY be prompted to update your table with a new order of columns in the composite primary key. You will need to either change it manually in the database or push the changes, but this may lead to data loss, etc.If you are using
generate, you MAY also be prompted to update your table with a new order of columns in the composite primary key. You can either keep that migration or skip it by emptying the SQL migration file.
If nothing works for you and you are blocked, please reach out to me @AndriiSherman. I will try to help you!
Bug fixes
[BUG] When using double type columns, import is not inserted
[BUG] A number value is specified as the default for a column of type char
[BUG]: drizzle-kit generate succeeds but generates invalid SQL for default() - Postgres
[BUG]: error: column is of type integer but default expression is of type integer
[BUG]: Default value in array generating wrong migration file
- 0.23.x
0.23.2
5 Aug 2024Fixed a bug in PostgreSQL with push and introspect where the
schemaFilterobject was passed. It was detecting enums even in schemas that were not defined in the schemaFilter.Fixed the
drizzle-kit upcommand to work as expected, starting from the sequences release.
0.23.1
30 Jul 2024🐛 Re-export
InferModelfromdrizzle-orm
0.23.0
10 Jul 2024🎉 Added Knex and Kysely adapters! They allow you to manage the schemas and migrations with Drizzle and query the data with your favorite query builder. See documentation for more details:
🎉 Added "type maps" to all entities. You can access them via the special
_property. For example:const users = mysqlTable('users', { id: int('id').primaryKey(), name: text('name').notNull(), }); type UserFields = typeof users['_']['columns']; type InsertUser = typeof users['_']['model']['insert'];Full documentation on the type maps is coming soon.
🎉 Added
.$type()method to all column builders to allow overriding the data type. It also replaces the optional generics on columns.// Before const test = mysqlTable('test', { jsonField: json<Data>('json_field'), }); // After const test = mysqlTable('test', { jsonField: json('json_field').$type<Data>(), });
🎉 Added Knex and Kysely adapters! They allow you to manage the schemas and migrations with Drizzle and query the data with your favorite query builder. See documentation for more details:
🎉 Added "type maps" to all entities. You can access them via the special
_property. For example:const users = mysqlTable('users', { id: int('id').primaryKey(), name: text('name').notNull(), }); type UserFields = typeof users['_']['columns']; type InsertUser = typeof users['_']['model']['insert'];Full documentation on the type maps is coming soon.
🎉 Added
.$type()method to all column builders to allow overriding the data type. It also replaces the optional generics on columns.// Before const test = mysqlTable('test', { jsonField: json<Data>('json_field'), }); // After const test = mysqlTable('test', { jsonField: json('json_field').$type<Data>(), });❗ Changed syntax for text-based enum columns:
// Before const test = mysqlTable('test', { role: text<'admin' | 'user'>('role'), }); // After const test = mysqlTable('test', { role: text('role', { enum: ['admin', 'user'] }), });🎉 Allowed passing an array of values into
.insert().values()directly without spreading:const users = mysqlTable('users', { id: int('id').primaryKey(), name: text('name').notNull(), }); await users.insert().values([ { name: 'John' }, { name: 'Jane' }, ]);The spread syntax is now deprecated and will be removed in one of the next releases.
🎉 Added "table creators" to allow for table name customization:
import { mysqlTableCreator } from 'drizzle-orm/mysql-core'; const mysqlTable = mysqlTableCreator((name) => `myprefix_${name}`); const users = mysqlTable('users', { id: int('id').primaryKey(), name: text('name').notNull(), }); // Users table is a normal table, but its name is `myprefix_users` in runtime🎉 Implemented support for selecting/joining raw SQL expressions:
// select current_date + s.a as dates from generate_series(0,14,7) as s(a); const result = await db .select({ dates: sql`current_date + s.a`, }) .from(sql`generate_series(0,14,7) as s(a)`);🐛 Fixed a lot of bugs from user feedback on GitHub and Discord (thank you! ❤). Fixes #293 #301 #276 #269 #253 #311 #312
- 0.22.x
0.22.0
31 May 2024🎉 Introduced a standalone query builder that can be used without a DB connection:
import { queryBuilder as qb } from 'drizzle-orm/pg-core'; const query = qb.select().from(users).where(eq(users.name, 'Dan')); const { sql, params } = query.toSQL();🎉 Improved
WITH ... SELECTsubquery creation syntax to more resemble SQL:Before:
const regionalSales = db .select({ region: orders.region, totalSales: sql`sum(${orders.amount})`.as<number>('total_sales'), }) .from(orders) .groupBy(orders.region) .prepareWithSubquery('regional_sales'); await db.with(regionalSales).select(...).from(...);After:
const regionalSales = db .$with('regional_sales') .as( db .select({ region: orders.region, totalSales: sql<number>`sum(${orders.amount})`.as('total_sales'), }) .from(orders) .groupBy(orders.region), ); await db.with(regionalSales).select(...).from(...);
- 0.21.x
0.21.1
10 May 2024🎉 Added support for
HAVINGclause🎉 Added support for referencing selected fields in
.where(),.having(),.groupBy()and.orderBy()using an optional callback:await db .select({ id: citiesTable.id, name: sql<string>`upper(${citiesTable.name})`.as('upper_name'), usersCount: sql<number>`count(${users2Table.id})::int`.as('users_count'), }) .from(citiesTable) .leftJoin(users2Table, eq(users2Table.cityId, citiesTable.id)) .where(({ name }) => sql`length(${name}) >= 3`) .groupBy(citiesTable.id) .having(({ usersCount }) => sql`${usersCount} > 0`) .orderBy(({ name }) => name);
0.21.0
9 May 2024Added support for new migration folder structure and breakpoints feature, described in drizzle-kit release section
Fix
onUpdateNow()expression generation for default migration statementChar is undefined during introspection #9
Drizzle ORM 0.21.0 was released
Added support for new migration folder structure and breakpoints feature, described in drizzle-kit release section
Fix
onUpdateNow()expression generation for default migration statement
Support for PostgreSQL array types
export const salEmp = pgTable('sal_emp', { name: text('name').notNull(), payByQuarter: integer('pay_by_quarter').array(), schedule: text('schedule').array().array(), }); export const tictactoe = pgTable('tictactoe', { squares: integer('squares').array(3).array(3), });drizzle kit will generate
CREATE TABLE sal_emp ( name text, pay_by_quarter integer[], schedule text[][] ); CREATE TABLE tictactoe ( squares integer[3][3] );
Added composite primary key support to PostgreSQL and MySQL
PostgreSQL
import { primaryKey } from 'drizzle-orm/pg-core'; export const cpkTable = pgTable('table', { column1: integer('column1').default(10).notNull(), column2: integer('column2'), column3: integer('column3'), }, (table) => ({ cpk: primaryKey(table.column1, table.column2), }));MySQL
import { primaryKey } from 'drizzle-orm/mysql-core'; export const cpkTable = mysqlTable('table', { simple: int('simple'), columnNotNull: int('column_not_null').notNull(), columnDefault: int('column_default').default(100), }, (table) => ({ cpk: primaryKey(table.simple, table.columnDefault), }));Breaking changes
Folder structure was migrated to newer version
Before running any new migrations
drizzle-kitwill ask you to upgrade in a first placeMigration file structure < 0.17.0
📦 <project root> └ 📂 migrations └ 📂 20221207174503 ├ 📜 migration.sql ├ 📜 snapshot.json └ 📂 20230101104503 ├ 📜 migration.sql ├ 📜 snapshot.jsonMigration file structure >= 0.17.0
📦 <project root> └ 📂 migrations └ 📂 meta ├ 📜 _journal.json ├ 📜 0000_snapshot.json ├ 📜 0001_snapshot.json └ 📜 0000_icy_stranger.sql └ 📜 0001_strange_avengers.sqlUpgrading to 0.17.0
!(/changelogs/media/up_mysql.gif)
To easily migrate from previous folder structure to new you need to run
upcommand in drizzle kit. It's a great helper to upgrade your migrations to new format on each drizzle kit major updatedrizzle-kit up:<dialect> # dialects: `pg`, `mysql`, `sqlite` # example for pg drizzle-kit up:pg
New Features
New
drizzle-kitcommand calleddropIn a case you think some of migrations were generated in a wrong way or you have made migration simultaneously with other developers you can easily rollback it by running simple command
Warning:
Make sure you are dropping migrations that were not applied to your databasedrizzle-kit drop
This command will show you a list of all migrations you have and you'll need just to choose migration you want to drop. After that
drizzle-kitwill do all the hard work on deleting migration files!(/changelogs/media/drop.gif)
New
drizzle-kitoption--breakpointsforgenerateandintrospectcommandsIf particular driver doesn't support running multiple quries in 1 execution you can use
--breakpoints.drizzle-kitwill generate current sqlCREATE TABLE `users` ( `id` int PRIMARY KEY NOT NULL, `full_name` text NOT NULL, ); --> statement-breakpoint CREATE TABLE `table` ( `id` int PRIMARY KEY NOT NULL, `phone` int, );
Using it
drizzle-ormwill split all sql files by statements and execute them separatelyAdd
drizzle-kit introspectfor MySQL dialectYou can introspect your mysql database using
introspect:mysqlcommanddrizzle-kit introspect:mysql --out ./migrations --connectionString mysql://user:password@127.0.0.1:3306/database
!(/changelogs/media/introspect_mysql.gif)
Support for glob patterns for schema path
Usage example in
clidrizzle-kit generate:pg --out ./migrations --schema ./core/**/*.ts ./database/schema.ts
Usage example in
drizzle.config{ "out: "./migrations", "schema": ["./core/**/*.ts", "./database/schema.ts"] }Bug Fixes and improvements
Postgres dialect
GitHub issue fixes
Char is undefined during introspection #9
When unknown type is detected, would be nice to emit a TODO comment instead of undefined #8
"post_id" integer DEFAULT currval('posts_id_seq'::regclass) generates invalid TS #7
"ip" INET NOT NULL is not supported #6
"id" UUID NOT NULL DEFAULT uuid_generate_v4() type is not supported #5
Array fields end up as "undefined" in the schema #4
Timestamp is not in the import statement in schema.ts #3
Generated enums are not camel cased #2
Introspect improvements
Add support for composite PK's generation;
Add support for
cidr,inet,macaddr,macaddr8,smallserialAdd interval fields generation in schema, such as
minute to second,day to hour, etc.Add default values for
numericsAdd default values for
enums
MySQL dialect
Migration generation improvements
Add
autoincrementcreate, delete and update handlingAdd
on update current_timestamphandling for timestampsAdd data type changing, using
modifyAdd
not nullchanging, usingmodifyAdd
defaultdrop and create statementsFix
defaultsgeneration bugs, such as escaping, date strings, expressions, etc
Introspect improvements
Add
autoincrementto all supported typesAdd
fspfor time based data typesAdd precision and scale for
doubleMake time
{ mode: "string" }by defaultAdd defaults to
json,decimalandbinarydatatypesAdd
enumdata type generation
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.