changelogs/drizzle-orm/0.21.0.md
onUpdateNow() expression generation for default migration statementexport 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]
);
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),
}));
Before running any new migrations drizzle-kit will ask you to upgrade in a first place
Migration file structure < 0.17.0
š¦ <project root>
ā š migrations
ā š 20221207174503
ā š migration.sql
ā š snapshot.json
ā š 20230101104503
ā š migration.sql
ā š snapshot.json
Migration file structure >= 0.17.0
š¦ <project root>
ā š migrations
ā š meta
ā š _journal.json
ā š 0000_snapshot.json
ā š 0001_snapshot.json
ā š 0000_icy_stranger.sql
ā š 0001_strange_avengers.sql
To easily migrate from previous folder structure to new you need to run up command in drizzle kit. It's a great helper to upgrade your migrations to new format on each drizzle kit major update
drizzle-kit up:<dialect> # dialects: `pg`, `mysql`, `sqlite`
# example for pg
drizzle-kit up:pg
drizzle-kit command called dropIn 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 database
drizzle-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-kit will do all the hard work on deleting migration files
drizzle-kit option --breakpoints for generate and introspect commandsIf particular driver doesn't support running multiple quries in 1 execution you can use --breakpoints.
drizzle-kit will generate current sql
CREATE 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-orm will split all sql files by statements and execute them separately
drizzle-kit introspect for MySQL dialectYou can introspect your mysql database using introspect:mysql command
drizzle-kit introspect:mysql --out ./migrations --connectionString mysql://user:[email protected]:3306/database
Usage example in cli
drizzle-kit generate:pg --out ./migrations --schema ./core/**/*.ts ./database/schema.ts
Usage example in drizzle.config
{
"out: "./migrations",
"schema": ["./core/**/*.ts", "./database/schema.ts"]
}
GitHub issue fixes
Introspect improvements
cidr, inet, macaddr, macaddr8, smallserialminute to second, day to hour, etc.numericsenumsMigration generation improvements
autoincrement create, delete and update handlingon update current_timestamp handling for timestampsmodifynot null changing, using modifydefault drop and create statementsdefaults generation bugs, such as escaping, date strings, expressions, etcIntrospect improvements
autoincrement to all supported typesfsp for time based data typesdouble{ mode: "string" } by defaultjson, decimal and binary datatypesenum data type generation