-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
190 changed files
with
13,579 additions
and
4,168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# New Features | ||
|
||
### `drizzle-kit export` | ||
|
||
To 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 | ||
|
||
```ts | ||
// 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 | ||
```bash | ||
npx drizzle-kit export | ||
``` | ||
|
||
will output this string to console | ||
```bash | ||
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 tools | ||
|
||
```bash | ||
npx drizzle-kit export --sql | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Types breaking changes | ||
|
||
A few internal types were changed and extra generic types for length of column types were added in this release. It won't affect anyone, unless you are using those internal types for some custom wrappers, logic, etc. Here is a list of all types that were changed, so if you are relying on those, please review them before upgrading | ||
|
||
- `MySqlCharBuilderInitial` | ||
- `MySqlVarCharBuilderInitial` | ||
- `PgCharBuilderInitial` | ||
- `PgArrayBuilder` | ||
- `PgArray` | ||
- `PgVarcharBuilderInitial` | ||
- `PgBinaryVectorBuilderInitial` | ||
- `PgBinaryVectorBuilder` | ||
- `PgBinaryVector` | ||
- `PgHalfVectorBuilderInitial` | ||
- `PgHalfVectorBuilder` | ||
- `PgHalfVector` | ||
- `PgVectorBuilderInitial` | ||
- `PgVectorBuilder` | ||
- `PgVector` | ||
- `SQLiteTextBuilderInitial` | ||
|
||
# New Features | ||
|
||
- Added new function `getViewSelectedFields` | ||
- Added `$inferSelect` function to views | ||
- Added `InferSelectViewModel` type for views | ||
- Added `isView` function | ||
|
||
# Validator packages updates | ||
|
||
- `drizzle-zod` has been completely rewritten. You can find detailed information about it [here](https://github.com/drizzle-team/drizzle-orm/blob/main/changelogs/drizzle-zod/0.6.0.md) | ||
- `drizzle-valibot` has been completely rewritten. You can find detailed information about it [here](https://github.com/drizzle-team/drizzle-orm/blob/main/changelogs/drizzle-valibot/0.3.0.md) | ||
- `drizzle-typebox` has been completely rewritten. You can find detailed information about it [here](https://github.com/drizzle-team/drizzle-orm/blob/main/changelogs/drizzle-typebox/0.2.0.md) | ||
|
||
Thanks to @L-Mario564 for making more updates than we expected to be shipped in this release. We'll copy his message from a PR regarding improvements made in this release: | ||
|
||
- Output for all packages are now unminified, makes exploring the compiled code easier when published to npm. | ||
- Smaller footprint. Previously, we imported the column types at runtime for each dialect, meaning that for example, if you're just using Postgres then you'd likely only have drizzle-orm and drizzle-orm/pg-core in the build output of your app; however, these packages imported all dialects which could lead to mysql-core and sqlite-core being bundled as well even if they're unused in your app. This is now fixed. | ||
- Slight performance gain. To determine the column data type we used the is function which performs a few checks to ensure the column data type matches. This was slow, as these checks would pile up every quickly when comparing all data types for many fields in a table/view. The easier and faster alternative is to simply go off of the column's columnType property. | ||
- Some changes had to be made at the type level in the ORM package for better compatibility with drizzle-valibot. | ||
|
||
And a set of new features | ||
|
||
- `createSelectSchema` function now also accepts views and enums. | ||
- New function: `createUpdateSchema`, for use in updating queries. | ||
- New function: `createSchemaFactory`, to provide more advanced options and to avoid bloating the parameters of the other schema functions | ||
|
||
# Bug fixes | ||
|
||
- [[FEATURE]: publish packages un-minified](https://github.com/drizzle-team/drizzle-orm/issues/2247) | ||
- [Don't allow unknown keys in drizzle-zod refinement](https://github.com/drizzle-team/drizzle-orm/issues/573) | ||
- [[BUG]:drizzle-zod not working with pgSchema](https://github.com/drizzle-team/drizzle-orm/issues/1458) | ||
- [Add createUpdateSchema to drizzle-zod](https://github.com/drizzle-team/drizzle-orm/issues/503) | ||
- [[BUG]:drizzle-zod produces wrong type](https://github.com/drizzle-team/drizzle-orm/issues/1110) | ||
- [[BUG]:Drizzle-zod:Boolean and Serial types from Schema are defined as enum<unknown> when using CreateInsertSchema and CreateSelectSchema](https://github.com/drizzle-team/drizzle-orm/issues/1327) | ||
- [[BUG]: Drizzle typebox enum array wrong schema and type](https://github.com/drizzle-team/drizzle-orm/issues/1345) | ||
- [[BUG]:drizzle-zod not working with pgSchema](https://github.com/drizzle-team/drizzle-orm/issues/1458) | ||
- [[BUG]: drizzle-zod not parsing arrays correctly](https://github.com/drizzle-team/drizzle-orm/issues/1609) | ||
- [[BUG]: Drizzle typebox not supporting array](https://github.com/drizzle-team/drizzle-orm/issues/1810) | ||
- [[FEATURE]: Export factory functions from drizzle-zod to allow usage with extended Zod classes](https://github.com/drizzle-team/drizzle-orm/issues/2245) | ||
- [[FEATURE]: Add support for new pipe syntax for drizzle-valibot](https://github.com/drizzle-team/drizzle-orm/issues/2358) | ||
- [[BUG]: drizzle-zod's createInsertSchema() can't handle column of type vector](https://github.com/drizzle-team/drizzle-orm/issues/2424) | ||
- [[BUG]: drizzle-typebox fails to map geometry column to type-box schema](https://github.com/drizzle-team/drizzle-orm/issues/2516) | ||
- [[BUG]: drizzle-valibot does not provide types for returned schemas](https://github.com/drizzle-team/drizzle-orm/issues/2521) | ||
- [[BUG]: Drizzle-typebox types SQLite real field to string](https://github.com/drizzle-team/drizzle-orm/issues/2524) | ||
- [[BUG]: drizzle-zod: documented usage generates type error with exactOptionalPropertyTypes](https://github.com/drizzle-team/drizzle-orm/issues/2550) | ||
- [[BUG]: drizzle-zod does not respect/count db type range](https://github.com/drizzle-team/drizzle-orm/issues/2737) | ||
- [[BUG]: drizzle-zod not overriding optional](https://github.com/drizzle-team/drizzle-orm/issues/2755) | ||
- [[BUG]:drizzle-zod doesn't accept custom id value](https://github.com/drizzle-team/drizzle-orm/issues/2957) | ||
- [[FEATURE]: Support for Database Views in Drizzle Zod](https://github.com/drizzle-team/drizzle-orm/issues/3398) | ||
- [[BUG]: drizzle-valibot return type any](https://github.com/drizzle-team/drizzle-orm/issues/3621) | ||
- [[BUG]: drizzle-zod Type generation results in undefined types](https://github.com/drizzle-team/drizzle-orm/issues/3645) | ||
- [[BUG]: GeneratedAlwaysAs](https://github.com/drizzle-team/drizzle-orm/issues/3511) | ||
- [[FEATURE]: $inferSelect on a view](https://github.com/drizzle-team/drizzle-orm/issues/2610) | ||
- [[BUG]:Can't infer props from view in schema](https://github.com/drizzle-team/drizzle-orm/issues/3392) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Closed [[FEATURE]: Add more flexible typing for usage with exactOptionalPropertyTypes](https://github.com/drizzle-team/drizzle-orm/issues/2742) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# New features | ||
|
||
## `USE INDEX`, `FORCE INDEX` and `IGNORE INDEX` for MySQL | ||
|
||
In MySQL, the statements USE INDEX, FORCE INDEX, and IGNORE INDEX are hints used in SQL queries to influence how the query optimizer selects indexes. These hints provide fine-grained control over index usage, helping optimize performance when the default behavior of the optimizer is not ideal. | ||
|
||
### Use Index | ||
|
||
The `USE INDEX` hint suggests to the optimizer which indexes to consider when processing the query. The optimizer is not forced to use these indexes but will prioritize them if they are suitable. | ||
|
||
```ts | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { useIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
### Ignore Index | ||
|
||
The `IGNORE INDEX` hint tells the optimizer to avoid using specific indexes for the query. MySQL will consider all other indexes (if any) or perform a full table scan if necessary. | ||
|
||
```ts | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { ignoreIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
### Force Index | ||
|
||
The `FORCE INDEX` hint forces the optimizer to use the specified index(es) for the query. If the specified index cannot be used, MySQL will not fall back to other indexes; it might resort to a full table scan instead. | ||
|
||
```ts copy | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { forceIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
You can also combine those hints and use multiple indexes in a query if you need |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
## Bug fixes | ||
|
||
- https://github.com/drizzle-team/drizzle-orm/issues/3644 | ||
- seeding a table with columns that have .default(sql``) will result in an error | ||
|
||
## Features | ||
|
||
- added support for postgres uuid columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, uuid } from "drizzle-orm/pg-core"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { seed } from "drizzle-seed"; | ||
|
||
const users = pgTable("users", { | ||
uuid: uuid("uuid"), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
// You can let it seed automatically | ||
// await seed(db, { users }); | ||
|
||
// Alternatively, you can manually specify the generator in refine. | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
uuid: funcs.uuid(), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for postgres array columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, integer, text, varchar } from "drizzle-orm/pg-core"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { seed } from "drizzle-seed"; | ||
|
||
const users = pgTable("users", { | ||
id: integer().primaryKey(), | ||
name: text().notNull(), | ||
phone_numbers: varchar({ length: 256 }).array(), | ||
}); | ||
``` | ||
|
||
You can specify the `arraySize` parameter in generator options, like `funcs.phoneNumber({ arraySize: 3 })`, to generate 1D arrays. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
phone_numbers: funcs.phoneNumber({ arraySize: 3 }), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
Alternatively, you can let it seed automatically, and it will handle arrays of any dimension. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for cyclic tables | ||
|
||
You can now seed tables with cyclic relations. | ||
|
||
```ts | ||
import type { AnyPgColumn } from "drizzle-orm/pg-core"; | ||
import { | ||
foreignKey, | ||
integer, | ||
pgTable, | ||
serial, | ||
varchar, | ||
} from "drizzle-orm/pg-core"; | ||
|
||
export const modelTable = pgTable( | ||
"model", | ||
{ | ||
id: serial().primaryKey(), | ||
name: varchar().notNull(), | ||
defaultImageId: integer(), | ||
}, | ||
(t) => [ | ||
foreignKey({ | ||
columns: [t.defaultImageId], | ||
foreignColumns: [modelImageTable.id], | ||
}), | ||
] | ||
); | ||
|
||
export const modelImageTable = pgTable("model_image", { | ||
id: serial().primaryKey(), | ||
url: varchar().notNull(), | ||
caption: varchar(), | ||
modelId: integer() | ||
.notNull() | ||
.references((): AnyPgColumn => modelTable.id), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { modelTable, modelImageTable }); | ||
} | ||
|
||
main(); | ||
``` |
Oops, something went wrong.