diff --git a/changelogs/drizzle-kit/0.26.0.md b/changelogs/drizzle-kit/0.26.0.md new file mode 100644 index 000000000..8e054812b --- /dev/null +++ b/changelogs/drizzle-kit/0.26.0.md @@ -0,0 +1,122 @@ +# New Features + +## Checks support in `drizzle-kit` + +You can use drizzle-kit to manage your `check` constraint defined in drizzle-orm schema definition + +For example current drizzle table: + +```ts +import { sql } from "drizzle-orm"; +import { check, pgTable } from "drizzle-orm/pg-core"; + +export const users = pgTable( + "users", + (c) => ({ + id: c.uuid().defaultRandom().primaryKey(), + username: c.text().notNull(), + age: c.integer(), + }), + (table) => ({ + checkConstraint: check("age_check", sql`${table.age} > 21`), + }) +); +``` + +will be generated into + +```sql +CREATE TABLE IF NOT EXISTS "users" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "username" text NOT NULL, + "age" integer, + CONSTRAINT "age_check" CHECK ("users"."age" > 21) +); +``` + +The same is supported in all dialects + +### Limitations + +- `generate` will work as expected for all check constraint changes. +- `push` will detect only check renames and will recreate the constraint. All other changes to SQL won't be detected and will be ignored. + +So, if you want to change the constraint's SQL definition using only `push`, you would need to manually comment out the constraint, `push`, then put it back with the new SQL definition and `push` one more time. + +## Views support in `drizzle-kit` + +You can use drizzle-kit to manage your `views` defined in drizzle-orm schema definition. It will work with all existing dialects and view options + +### PostgreSQL + +For example current drizzle table: + +```ts +import { sql } from "drizzle-orm"; +import { + check, + pgMaterializedView, + pgTable, + pgView, +} from "drizzle-orm/pg-core"; + +export const users = pgTable( + "users", + (c) => ({ + id: c.uuid().defaultRandom().primaryKey(), + username: c.text().notNull(), + age: c.integer(), + }), + (table) => ({ + checkConstraint: check("age_check", sql`${table.age} > 21`), + }) +); + +export const simpleView = pgView("simple_users_view").as((qb) => + qb.select().from(users) +); + +export const materializedView = pgMaterializedView( + "materialized_users_view" +).as((qb) => qb.select().from(users)); +``` + +will be generated into + +```sql +CREATE TABLE IF NOT EXISTS "users" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "username" text NOT NULL, + "age" integer, + CONSTRAINT "age_check" CHECK ("users"."age" > 21) +); + +CREATE VIEW "public"."simple_users_view" AS (select "id", "username", "age" from "users"); + +CREATE MATERIALIZED VIEW "public"."materialized_users_view" AS (select "id", "username", "age" from "users"); +``` + +Views supported in all dialects, but materialized views are supported only in PostgreSQL + +#### Limitations + +- `generate` will work as expected for all view changes +- `push` limitations: + +1. If you want to change the view's SQL definition using only `push`, you would need to manually comment out the view, `push`, then put it back with the new SQL definition and `push` one more time. + +## Updates for PostgreSQL enums behavior + +We've updated enum behavior in Drizzle with PostgreSQL: + +- Add value after or before in enum: With this change, Drizzle will now respect the order of values in the enum and allow adding new values after or before a specific one. + +- Support for dropping a value from an enum: In this case, Drizzle will attempt to alter all columns using the enum to text, then drop the existing enum and create a new one with the updated set of values. After that, all columns previously using the enum will be altered back to the new enum. + +> If the deleted enum value was used by a column, this process will result in a database error. + +- Support for dropping an enum + +- Support for moving enums between schemas + +- Support for renaming enums diff --git a/changelogs/drizzle-orm/0.35.0.md b/changelogs/drizzle-orm/0.35.0.md new file mode 100644 index 000000000..92bafdff1 --- /dev/null +++ b/changelogs/drizzle-orm/0.35.0.md @@ -0,0 +1,85 @@ +# Important change after 0.34.0 release + +## Updated the init Drizzle database API + +The API from version 0.34.0 turned out to be unusable and needs to be changed. You can read more about our decisions in [this discussion](https://github.com/drizzle-team/drizzle-orm/discussions/3097) + +If you still want to use the new API introduced in 0.34.0, which can create driver clients for you under the hood, you can now do so +```ts +import { drizzle } from "drizzle-orm/node-postgres"; + +const db = drizzle(process.env.DATABASE_URL); +// or +const db = drizzle({ + connection: process.env.DATABASE_URL +}); +const db = drizzle({ + connection: { + user: "...", + password: "...", + host: "...", + port: 4321, + db: "...", + }, +}); + +// if you need to pass logger or schema +const db = drizzle({ + connection: process.env.DATABASE_URL, + logger: true, + schema: schema, +}); +``` + +in order to not introduce breaking change - we will still leave support for deprecated API until V1 release. +It will degrade autocomplete performance in connection params due to `DatabaseDriver` | `ConnectionParams` types collision, +but that's a decent compromise against breaking changes + +```ts +import { drizzle } from "drizzle-orm/node-postgres"; +import { Pool } from "pg"; + +const client = new Pool({ connectionString: process.env.DATABASE_URL }); +const db = drizzle(client); // deprecated but available + +// new version +const db = drizzle({ + client: client, +}); +``` + +# New Features + +## New .orderBy() and .limit() functions in update and delete statements SQLite and MySQL + +You now have more options for the `update` and `delete` query builders in MySQL and SQLite + +**Example** + +```ts +await db.update(usersTable).set({ verified: true }).limit(2).orderBy(asc(usersTable.name)); + +await db.delete(usersTable).where(eq(usersTable.verified, false)).limit(1).orderBy(asc(usersTable.name)); +``` + +## New `drizzle.mock()` function + +There were cases where you didn't need to provide a driver to the Drizzle object, and this served as a workaround +```ts +const db = drizzle({} as any) +``` + +Now you can do this using a mock function +```ts +const db = drizzle.mock() +``` + +There is no valid production use case for this, but we used it in situations where we needed to check types, etc., without making actual database calls or dealing with driver creation. If anyone was using it, please switch to using mocks now + +# Internal updates + +- Upgraded TS in codebase to the version 5.6.3 + +# Bug fixes + +- [[BUG]: New $count API error with @neondatabase/serverless](https://github.com/drizzle-team/drizzle-orm/issues/3081) \ No newline at end of file diff --git a/drizzle-kit/package.json b/drizzle-kit/package.json index cf771296a..ce2de1468 100644 --- a/drizzle-kit/package.json +++ b/drizzle-kit/package.json @@ -1,6 +1,6 @@ { "name": "drizzle-kit", - "version": "0.25.0", + "version": "0.26.0", "homepage": "https://orm.drizzle.team", "keywords": [ "drizzle", diff --git a/drizzle-orm/package.json b/drizzle-orm/package.json index cef1a7aef..bd3221754 100644 --- a/drizzle-orm/package.json +++ b/drizzle-orm/package.json @@ -1,6 +1,6 @@ { "name": "drizzle-orm", - "version": "0.34.1", + "version": "0.35.0", "description": "Drizzle ORM package for SQL databases", "type": "module", "scripts": {