-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' of https://github.com/drizzle-team/drizzle-orm in…
…to drizzle-kit/export-sql
- Loading branch information
Showing
88 changed files
with
4,976 additions
and
792 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 @@ | ||
- Fix SingleStore generate migrations command |
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,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,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(); | ||
``` |
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,87 @@ | ||
This version fully updates `drizzle-typebox` integration and makes sure it's compatible with newer typebox versions | ||
|
||
# Breaking Changes | ||
|
||
> You must also have Drizzle ORM v0.38.0 or greater and Typebox v0.34.8 or greater installed. | ||
- When refining a field, if a schema is provided instead of a callback function, it will ignore the field's nullability and optional status. | ||
- Some data types have more specific schemas for improved validation | ||
|
||
# Improvements | ||
|
||
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. | ||
|
||
# New features | ||
|
||
- `createSelectSchema` function now also accepts views and enums. | ||
|
||
```ts | ||
import { pgEnum } from 'drizzle-orm/pg-core'; | ||
import { createSelectSchema } from 'drizzle-typebox'; | ||
import { Value } from '@sinclair/typebox/value'; | ||
|
||
const roles = pgEnum('roles', ['admin', 'basic']); | ||
const rolesSchema = createSelectSchema(roles); | ||
const parsed: 'admin' | 'basic' = Value.Parse(rolesSchema, ...); | ||
|
||
const usersView = pgView('users_view').as((qb) => qb.select().from(users).where(gt(users.age, 18))); | ||
const usersViewSchema = createSelectSchema(usersView); | ||
const parsed: { id: number; name: string; age: number } = Value.Parse(usersViewSchema, ...); | ||
``` | ||
|
||
- New function: `createUpdateSchema`, for use in updating queries. | ||
|
||
```ts copy | ||
import { pgTable, text, integer } from 'drizzle-orm/pg-core'; | ||
import { createUpdateSchema } from 'drizzle-typebox'; | ||
import { Value } from '@sinclair/typebox/value'; | ||
|
||
const users = pgTable('users', { | ||
id: integer().generatedAlwaysAsIdentity().primaryKey(), | ||
name: text().notNull(), | ||
age: integer().notNull() | ||
}); | ||
|
||
const userUpdateSchema = createUpdateSchema(users); | ||
|
||
const user = { id: 5, name: 'John' }; | ||
const parsed: { name?: string | undefined, age?: number | undefined } = Value.Parse(userUpdateSchema, user); // Error: `id` is a generated column, it can't be updated | ||
|
||
const user = { age: 35 }; | ||
const parsed: { name?: string | undefined, age?: number | undefined } = Value.Parse(userUpdateSchema, user); // Will parse successfully | ||
await db.update(users).set(parsed).where(eq(users.name, 'Jane')); | ||
``` | ||
|
||
- New function: `createSchemaFactory`, to provide more advanced options and to avoid bloating the parameters of the other schema functions | ||
|
||
```ts copy | ||
import { pgTable, text, integer } from 'drizzle-orm/pg-core'; | ||
import { createSchemaFactory } from 'drizzle-typebox'; | ||
import { t } from 'elysia'; // Extended Typebox instance | ||
|
||
const users = pgTable('users', { | ||
id: integer().generatedAlwaysAsIdentity().primaryKey(), | ||
name: text().notNull(), | ||
age: integer().notNull() | ||
}); | ||
|
||
const { createInsertSchema } = createSchemaFactory({ typeboxInstance: t }); | ||
|
||
const userInsertSchema = createInsertSchema(users, { | ||
// We can now use the extended instance | ||
name: (schema) => t.Number({ ...schema }, { error: '`name` must be a string' }) | ||
}); | ||
``` | ||
|
||
- Full support for PG arrays | ||
|
||
```ts | ||
pg.dataType().array(...); | ||
|
||
// Schema | ||
Type.Array(baseDataTypeSchema, { minItems: size, maxItems: size }); | ||
``` |
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,67 @@ | ||
This version fully updates `drizzle-valibot` integration and makes sure it's compatible with newer valibot versions | ||
|
||
# Breaking Changes | ||
|
||
> You must also have Drizzle ORM v0.38.0 or greater and Valibot v1.0.0-beta.7 or greater installed. | ||
- When refining a field, if a schema is provided instead of a callback function, it will ignore the field's nullability and optional status. | ||
- Some data types have more specific schemas for improved validation | ||
|
||
# Improvements | ||
|
||
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. | ||
|
||
# New features | ||
|
||
- `createSelectSchema` function now also accepts views and enums. | ||
|
||
```ts copy | ||
import { pgEnum } from 'drizzle-orm/pg-core'; | ||
import { createSelectSchema } from 'drizzle-valibot'; | ||
import { parse } from 'valibot'; | ||
|
||
const roles = pgEnum('roles', ['admin', 'basic']); | ||
const rolesSchema = createSelectSchema(roles); | ||
const parsed: 'admin' | 'basic' = parse(rolesSchema, ...); | ||
|
||
const usersView = pgView('users_view').as((qb) => qb.select().from(users).where(gt(users.age, 18))); | ||
const usersViewSchema = createSelectSchema(usersView); | ||
const parsed: { id: number; name: string; age: number } = parse(usersViewSchema, ...); | ||
``` | ||
|
||
- New function: `createUpdateSchema`, for use in updating queries. | ||
|
||
```ts copy | ||
import { pgTable, text, integer } from 'drizzle-orm/pg-core'; | ||
import { createUpdateSchema } from 'drizzle-valibot'; | ||
import { parse } from 'valibot'; | ||
|
||
const users = pgTable('users', { | ||
id: integer().generatedAlwaysAsIdentity().primaryKey(), | ||
name: text().notNull(), | ||
age: integer().notNull() | ||
}); | ||
|
||
const userUpdateSchema = createUpdateSchema(users); | ||
|
||
const user = { id: 5, name: 'John' }; | ||
const parsed: { name?: string | undefined, age?: number | undefined } = parse(userUpdateSchema, user); // Error: `id` is a generated column, it can't be updated | ||
|
||
const user = { age: 35 }; | ||
const parsed: { name?: string | undefined, age?: number | undefined } = parse(userUpdateSchema, user); // Will parse successfully | ||
await db.update(users).set(parsed).where(eq(users.name, 'Jane')); | ||
``` | ||
|
||
- Full support for PG arrays | ||
|
||
```ts | ||
pg.dataType().array(...); | ||
|
||
// Schema | ||
z.array(baseDataTypeSchema).length(size); | ||
``` |
Oops, something went wrong.