Releases: drizzle-team/drizzle-orm
v1.0.0-beta.8
drizzle-seed updates
Bug fixes
- [BUG]: drizzle seed doesn't work with libSQL
- [BUG]: Seed UUIDs not compatible with Zod/v4
- [BUG]: drizzle seed generates invalid input value (number) for enum strings (pg)
- [BUG]: drizzle seed breaks serial sequence sync with Postgres serial type
Features
ignore column in refinements
Now you can let drizzle-seed know if you want to ignore column during seeding.
// schema.ts
import { integer, pgTable, text } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: integer().primaryKey(),
name: text().notNull(),
age: integer(),
photo: text(),
});// index.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";
import * as schema from "./schema.ts";
async function main() {
const db = drizzle(process.env["DATABASE_URL"]!);
await seed(db, schema).refine((f) => ({
users: {
count: 5,
columns: {
name: f.fullName(),
photo: false, // the photo column will not be seeded, allowing the database to use its default value.
},
},
}));
}
main();Improvements
Added min, max parameters to time generator
await seed(db, { timeTable: schema.timeTable }).refine((funcs) => ({
timeTable: {
count,
columns: {
time: funcs.time({
min: "13:12:13",
max: "15:12:13",
}),
},
},
}));Added min, max parameters to timestamp generator
await seed(db, { timestampTable: schema.timestampTable }).refine((funcs) => ({
timestampTable: {
count,
columns: {
timestamp: funcs.timestamp({
min: "2025-03-07 13:12:13.123Z",
max: "2025-03-09 15:12:13.456Z",
}),
},
},
}));Added min, max parameters to datetime generator
await seed(db, { datetimeTable: schema.datetimeTable }).refine((funcs) => ({
datetimeTable: {
count,
columns: {
datetime: funcs.datetime({
min: "2025-03-07 13:12:13Z",
max: "2025-03-09 15:12:13Z",
}),
},
},
}));PostgreSQL sequences updating after seed
drizzle-seed iterates through each column in a table, selects columns of type smallint, integer, bigint, smallserial, serial, or bigserial, and (if a sequence exists) updates it to the column’s maximum seeded value.
select setval(pg_get_serial_sequence('"schema_name"."table_name"', 'column_name'), 3, true);Breaking changes
uuid generator was changed and upgraded to v4
await seed(db, { table }).refine((f) => ({
table: {
columns: {
// AA97B177-9383-4934-8543-0F91A7A02836
// ^
// 1
// the digit at position 1 is always one of '8', '9', 'A' or 'B'
column1: f.uuid(),
}
}
}))Reason for upgrade
UUID values generated by the old version of the uuid generator fail Zod’s v4 UUID validation.
example
import { createSelectSchema } from 'drizzle-zod';
import { seed } from 'drizzle-seed';
await seed(db, { uuidTest: schema.uuidTest }, { count: 1 }).refine((funcs) => ({
uuidTest: {
columns: {
col1: funcs.uuid()
}
}
})
);
const uuidSelectSchema = createSelectSchema(schema.uuidTest);
const res = await db.select().from(schema.uuidTest);
// the line below will throw an error when using old version of uuid generator
uuidSelectSchema.parse(res[0]);Usage
await seed(db, schema);
// or explicit
await seed(db, schema, { version: '4' });Switch to the old version
The previous version of uuid generator is v1.
await seed(db, schema, { version: '1' });To use the v2 generators while maintaining the v1 uuid generator:
await seed(db, schema, { version: '2' });To use the v3 generators while maintaining the v1 uuid generator:
await seed(db, schema, { version: '3' });v1.0.0-beta.6
Bug fixes
- [BUG]: 1.0.0-beta.2 - drizzle-kit push does consider json (jsonb) key order relevant
- [BUG]: drizzle-kit pull generates string instead of sql statement for default value
- [BUG]: Failed schema with d1 table
- [BUG]: drizzle-kit: push runs already applied migration
- [BUG]: Drizzle-Kit detects change when Composite Primary Key Columns are in different order than in schema definition
- [BUG]: drizzle-kit push always shows columns with custom types as changed even tho the type didn't change;
1.0.0-beta.5
Bug fixes
- [BUG]: error: type "serial" does not exist
- [BUG]: jsonb default with boolean literals gets generated truen instead of true
- [BUG]: MSSQL view incorrect syntax
- Fixed
blobcolumns in MySQL to work properly with RQB mapper
Changes to SQLite drizzle-kit up command
Important!
If you were already using SQLite in any
beta.xversion and have used thedrizzle-kit upcommand, you will not receive the latestupchanges from this release. If you are unable to reset migrations and start from scratch, you will need to contact us for support with upgrading
What was changed?
Handling of UNIQUE constraints in SQLite
In the new version drizzle-kit handles UNIQUE constraints. This decision was made because when a unique constraint is created it cannot be removed, whereas an index can be dropped
Previous version of Drizzle-Kit always created .unique() as a uniqueIndex and stored it in the snapshot that way. Because of this during an up we lack of sufficient information and if a user used .unique() an upped will generate a diff on generate and push
Solution:
We are replacing all unique constraints with uniqueIndex
uniqueIndex requires a name and the name must follow this format:
<table>_<column1>*_*<column2>_..._unique
Foreign key name handling in the old(pre 1.0) drizzle-kit
The old drizzle-kit did not handle foreign key names when generated sql migrations. A foreign key name could be defined in the ts schema, but it was not passed through when generating sql
export const table = sqliteTable("table", {
column1: integer(),
column2: integer()},
(t) => [
foreignKey({
name: "name",
columns: [t.column1],
foreignColumns: [t.column2],
}),
]
);
// no name provided
FOREIGN KEY (`timest`) REFERENCES `b`(`timest1`) ON UPDATE no action ON DELETE no actionOn introspect new drizzle-kit parses ddl to find constraint name, if no name found - use default name
After running drizzle-kit up the first push command will result in a diff that recreates the table (no name from db, but there is name in ts schema). To avoid this foreign key names should be removed - in that case no diff will be generated.
drizzle-kit generate command will behave as expected, no changes needed.
Bug in the old drizzle-kit related to foreign keys
If you add a column to an existing table that has a foreign key and specify onDelete or onUpdate, column will be added with the foreign key, but without those parameters
export const table = sqliteTable("table", {
column1: integer()
});
export const table = sqliteTable("table", {
column1: integer(),
column2: integer().references((): AnySQLiteColumn => table.column1,
{
onDelete: "set null",
onUpdate: "set default"
})
});
ALTER TABLE `table` ADD `column2` integer REFERENCES table(column1);There is no way to fix this in the old snapshot. It led to table recreation during subsequent push operations (in the pre-v1.0 drizzle-kit version)
New drizzle-kit will recreate table after push command with the correct SQL. When using generate command, no diffs will appear, but the actual database state may differ
1.0.0-beta.4
Regression issues fixed(from -beta.x releases)
- [BUG]: migrations.sort in migrator.js does nothing - migrations run in wrong order on Linux
- [BUG]: drizzle-kit generate not working without error
Issues fixed(from latest tag)
1.0.0-beta.3
Breaking changes (for MSSQL users)
The MSSQL snapshot has been upgraded to version 2. When you generate the next migration Drizzle Kit will ask you to update your current snapshot to version 2 if you have not done it already
"indexes.columns" field was updated in snapshot
This change allows to proper handle sql`` values inside index().on()
🎉 MySQL use/force/ingore index now accepts unique constraints
Bug fixes
- [BUG]: truncated tables on ALTER COLUMN statements
- [BUG]: Drizzle generates incorrect SQL migration for policy permission string changes
- [BUG]: Introspect PG _text type not recognized as an array
- [BUG]: drizzle-kit pull fails if db includes views which are not in "tablesFilter"
- [BUG]: AnySQLiteColumn in generated schema is not prefixed by "type" keyword
- [BUG]: drizzle-kit generate fails with "undefined" is not valid JSON
- [BUG]: Primary key migration fails when changing from one column to another
- [BUG]: Operator precedence of = and IS NULL is disrespected when using eq and isNull
0.45.1
v.1.0.0-beta.7
Bug fixes
-
[BUG]: Drizzle-kit does not consider prefix when generating migrations
-
[BUG]: drizzle-kit push removes migration table (doesn't recognize custom migration table name)
-
Push command now respects a custom migration schema or/and table from drizzle.config and ignores them during the execution
0.45.0
- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed
$onUpdatenot handlingSQLvalues (fixes #2388, tests implemented by L-Mario564 in #2911) - Fixed
pgmappers not handlingDateinstances inbun-sql:postgresqldriver responses fordate,timestamptypes (fixes #4493)
[email protected]
Bug fixes
- Fixed
algorythm=>algorithmtypo. - Fixed external dependencies in build configuration.
1.0.0-beta.2
We've introduced a lot of changes in this version, and something will definitely break. If anything goes wrong, you can either downgrade to version
1.0.0-beta.1or0.44.7, and please report any issues on GitHub or our Discord!
Don't forget to check
1.0.0-beta.1release notes as well: https://github.com/drizzle-team/drizzle-orm/blob/beta/changelogs/drizzle-orm/1.0.0-beta.1.md
Check the migration guide for RQBv1 to RQBv2 migration steps: https://orm.drizzle.team/docs/relations-v1-v2
Check new RQBv2 schema docs: https://orm.drizzle.team/docs/relations-v2
Check new RQBv2 query docs: https://orm.drizzle.team/docs/rqb-v2
New Features
MSSQL dialect
Drizzle now supports MSSQL in drizzle-orm, drizzle-kit and drizzle-seed packages. It support most of the columns, query builder capabilities, migration strategies, etc.
The only feature that is not yet supported is RQBv2
// Make sure to install the 'mssql' package
import { drizzle } from 'drizzle-orm/node-mssql';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');// Make sure to install the 'pg' package
import { drizzle } from 'drizzle-orm/node-mssql';
// You can specify any property from the mssql connection options
const db = drizzle({
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
const result = await db.execute('select 1');CockroachDB dialect
Drizzle now supports MSSQL in drizzle-orm, drizzle-kit and drizzle-seed packages. It support most of the columns, query builder capabilities, migration strategies, etc.
The only feature that is not yet supported is RQBv2
// Make sure to install the 'pg' package
import { drizzle } from 'drizzle-orm/cockroach';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');// Make sure to install the 'pg' package
import { drizzle } from 'drizzle-orm/cockroach';
// You can specify any property from the node-postgres connection options
const db = drizzle({
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true
}
});
const result = await db.execute('select 1');Relational Query Parts
In a case you need to separate relations config into several parts you can use defineRelationsPart helpers
import { defineRelations, defineRelationsPart } from 'drizzle-orm';
import * as schema from "./schema";
export const relations = defineRelations(schema, (r) => ({
users: {
invitee: r.one.users({
from: r.users.invitedBy,
to: r.users.id,
}),
posts: r.many.posts(),
}
}));
export const part = defineRelationsPart(schema, (r) => ({
posts: {
author: r.one.users({
from: r.posts.authorId,
to: r.users.id,
}),
}
}));and then you can provide it to the db instance
const db = drizzle(process.env.DB_URL, { relations: { ...relations, ...part } })Folders v3 migrations
Linked discussion: #2832
We've updated the migrations folder structure by:
- removing journal.json
- grouping SQL files and snapshots into separate migration folders
- removing the
drizzle-kit dropcommand
These changes eliminate potential Git conflicts with the journal file and simplify the process of dropping or fixing conflicted migrations
In upcoming beta releases, we'll introduce commutativity checks to help guide you through team migration conflicts, detect possible collisions, and suggest ways to resolve them
Commutativity discussion: #5005
To migrate previous folders to a new format you would need to run
drizzle-kit up
Full drizzle-kit rewrite
Architecture rewrite to close major kit and migration issues. We’ve completed a set of valuable and necessary updates to help us iterate faster, improve test coverage, and enhance overall stability.
Summary of work completed:
- Migrated from database snapshots to database DDL snapshots
- Reworked the entire architecture for detecting and applying diffs
- Added significant improvements for defaults, expressions, and types detection
- Reduced schema introspection time from 10 seconds to under 1 second by minimizing database calls and query complexity
- Added query hints and explain support for push
- Expanded test coverage - each test case now runs up to 6 different scenarios (e.g., push+push, pull+generate, etc.)
Added drizzle-kit pull --init
This flag will create a drizzle migration table in the database and will mark first pulled migration as applied, so you can contrinue iterating from there
schemaFilter behavior update
drizzle-kit will start managing all the schemas defined in your code. If you want to filter them, you can use schemaFilter
Previously, only the public schema was managed unless you explicitly added more schemas to schemaFilter.
It now also supports glob patterns, allowing you to filter schemas in any way you like
.enableRLS() deprecation
Previously to mark PostgreSQL table with RLS enabled you would need to:
// OLD syntax
pgTable('name', {}).enableRLS()We moved this option to a different place
pgTable.withRLS('users', {});Alias directly on columns
You can now add as alias to the column in a simple way:
const query = db
.select({ age: users.age.as('ageOfUser'), id: users.id.as('userId') })
.from(users)
.orderBy(asc(users.id.as('userId')));
MySQL new column types
We've added a few more MySQL column types:
- blob: https://orm.drizzle.team/docs/column-types/mysql#blob
- tinyblob: https://orm.drizzle.team/docs/column-types/mysql#tinyblob
- mediumblob: https://orm.drizzle.team/docs/column-types/mysql#mediumblob
- longblob: https://orm.drizzle.team/docs/column-types/mysql#longblob
More Updates and Fixes
- Fixed pg-native Pool detection in node-postgres transactions
- Allowed subqueries in select fields
- Updated typo algorythm => algorithm
- Fixed
$onUpdatenot handlingSQLvalues (fixes #2388, tests implemented by L-Mario564 in #2911) - Fixed
pgmappers not handlingDateinstances inbun-sql:postgresqldriver responses fordate,timestamptypes (fixes #4493)
Bugs fixed
This list is not full, we just had a time to get through some of the issues. This list will be updated through the next few weeks
-
[BUG]:
jsonbdefault with boolean literals gets generatedtrueninstead oftrue -
drizzle-kithas a dependency on a deprecated insecure package (@esbuild-kit/esm-loader) -
[BUG]: Drizzle-kit does not consider prefix when generating migrations
-
[BUG]: 1.0.0-beta.2 -
drizzle-kit pushdoes consider json (jsonb) key order relevant -
[BUG]: drizzle-kit pull generates string instead of sql statement for default value
-
[BUG]: drizzle-kit pull with PGlite driver produces empty foreign key column names
-
[BUG]: Drizzle-Kit push doesn't play well with enums (pgEnum)
-
[BUG]: pg-core - cannot create a
ginindex without theonlyoption -
[BUG]: Drizzle fails to execute query with string parameter even when column is varchar (PostgreSQL)
-
[FEATURE]: bigint string mode (works with identity + relations)
-
[[FEATURE]: Make it possible to include relations based on array ...