Skip to content

Releases: drizzle-team/drizzle-orm

v1.0.0-beta.8

31 Dec 16:15
a086f59

Choose a tag to compare

v1.0.0-beta.8 Pre-release
Pre-release

drizzle-seed updates

Bug fixes

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

25 Dec 10:10
a086f59

Choose a tag to compare

1.0.0-beta.5

23 Dec 17:46
a086f59

Choose a tag to compare

1.0.0-beta.5 Pre-release
Pre-release

Bug fixes

Changes to SQLite drizzle-kit up command

Important!

If you were already using SQLite in any beta.x version and have used the drizzle-kit up command, you will not receive the latest up changes 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 action

On 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

23 Dec 17:26
a086f59

Choose a tag to compare

1.0.0-beta.3

16 Dec 15:00
a086f59

Choose a tag to compare

1.0.0-beta.3 Pre-release
Pre-release

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

0.45.1

10 Dec 15:02
a086f59

Choose a tag to compare

  • Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden require() (#5107)

v.1.0.0-beta.7

31 Dec 14:18
a086f59

Choose a tag to compare

0.45.0

04 Dec 15:21
c445637

Choose a tag to compare

  • Fixed pg-native Pool detection in node-postgres transactions
  • Allowed subqueries in select fields
  • Updated typo algorythm => algorithm
  • Fixed $onUpdate not handling SQL values (fixes #2388, tests implemented by L-Mario564 in #2911)
  • Fixed pg mappers not handling Date instances in bun-sql:postgresql driver responses for date, timestamp types (fixes #4493)

[email protected]

04 Dec 15:21
c445637

Choose a tag to compare

Bug fixes

  • Fixed algorythm => algorithm typo.
  • Fixed external dependencies in build configuration.

1.0.0-beta.2

02 Dec 21:19
378b043

Choose a tag to compare

1.0.0-beta.2 Pre-release
Pre-release

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.1 or 0.44.7, and please report any issues on GitHub or our Discord!

Don't forget to check 1.0.0-beta.1 release 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 drop command

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:

More Updates and Fixes

  • Fixed pg-native Pool detection in node-postgres transactions
  • Allowed subqueries in select fields
  • Updated typo algorythm => algorithm
  • Fixed $onUpdate not handling SQL values (fixes #2388, tests implemented by L-Mario564 in #2911)
  • Fixed pg mappers not handling Date instances in bun-sql:postgresql driver responses for date, timestamp types (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

Read more