forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Check for Pg: -added check constraints to migrate, pull, push - added tests * added check constraints to mysql added some tests * - added sqlite, turso checks - added and updated tests * removed console.log merged beta to branch * rewrote introspect tests added introspect tests for checks * added progress callbacks for introspect with checks * updated tests for introspect * Implement limit and order by in MySQL * Add limit and order by to update and delete in SQLite * Format * Update SQLite test * Format * added postgresql generate handling for views * added support for views and materialized views in postgres (push + introspect + generate) * fixed build errors * added alter for using * added psql rename views and change schema handlings * added generate for mysql views * added introspect for mysql views * Added sqlite and libsql view handling * added all tests for all dialect views. updated introspect tests * Updated introspect tests * minor fixes * fixed numeric introspect in pg * fixed introspect numeric in pg * fixed introspect numeric pg * fixed sqlite + libsql alter existing handling * updated psql introspect + sqlite introspect for views * added progress callback to views. changed query columns for materialized views * updated pg introspect columns query. updated mysql test. * Updated enum handling for generate. Adde drop, add value, rename, set schema. Updated tests * made test for enum ordering for push * Added neon-serverless (websocket) tests, fixed neon-serverless session's lack of own count procedure (issue drizzle-team#3081) * fixed lockfile * Added leftover data deletion, imported table from common instead of re-creating locally * Fixed lack of custom schema cleanup on locally remade skipped tests of neon-serverless * squash add + drop enum values to drop only * Upgrade to TS 5.6.3 * removed commented code * Remove global set for node-postgres, neon and vercel; move to on per-query * Fix import * Fix test * Fix view tests * Check tests with docker * Update tests * Skip sqljs * Add ignore on neon * removed console logs in tests * Updated drizzle constructors, removed monodriver * Fixed type error * Fixed sqlite instance checks * Fixed mysql rename view sql statement * Fixed tests, added MockDriver & mock support for reworked drivers * Added `drizzle.mock()`, reworked replicas tests * Fixed neon client identification * Removed `bun-sqlite` from import tests * Added missing connectionString param * Fixed broken connection, added missing cases * Updated versions for orm and kit --------- Co-authored-by: Aleksandr Sherman <[email protected]> Co-authored-by: Mario564 <[email protected]> Co-authored-by: Sukairo-02 <[email protected]> Co-authored-by: Sergey Reka <[email protected]>
- Loading branch information
1 parent
6974798
commit 6f4fc4c
Showing
243 changed files
with
14,561 additions
and
3,410 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,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 |
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,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) |
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
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
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
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
Oops, something went wrong.