Drizzle Team

DT

Drizzle Team

The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!

Join

Error with drizzle-kit push

`node:internal/modules/cjs/loader:1251 throw err; ^ Error: Cannot find module 'drizzle-orm/casing'...

How to use sub query or CTE inside values method of insert?

I want to the results from CTE or sub query inside the select ``` const tableOneSubQuery = db.select({name: tableOne.columnOne}).from(tableOne).as('table_one_sub_query'); ...

many to many relation to same table with one relation field

I would like to depict the following scenario. There is a table “Avatars” which has a relation “Friends” that refers to itself, i.e. the table “Avatars”. Something like that: ```js...

Error when running migrations in newest drizzle-kit

When running a migration (drizzle-kit generate), I'm getting the following error: "(0 , import_pg_core.isPgSequence) is not a function" I'm using drizzle-orm 0.34.1 and drizzle-kit 0.24.0. ...

Need help migrating from "reference" declarations to "foreignKeys"

I'm doing some refactoring on our codebase (to eliminate circular dependencies) One of the main culprits is the <name>.table.ts files we have defined for our schema. I want to avoid generating unnecessary migrations, so was trying to use the same names that were automatically assigned for the references....

Can i share drizzle transaction with knex.js's transaction (postgresql)

If i can do this, i'm able to gradually migrate from knex.js

Count filtered results

Hello, Is there a way to see the count for Filtered results?...

How to automatically run migration on NextJS start

The docs is not clear on how to do it. It still uses npx tsx src/index.ts which is a CLI command instead of runtime.
No description

Natively write SQL functions/triggers with Drizzle?

Is it possible to, for example, write this kind of logic directly in Drizzle's schema? ```sql -- Checks if a user already has an active ban before inserting a new one. CREATE OR REPLACE FUNCTION check_active_ban() RETURNS TRIGGER AS $$...

[SOLVED] "Not enough info to infer relation", many-to-many junction table w/ postgres

I have read the posts online that say you must define relation names on both sides, and I already did that, but it still isn't working. Can anyone else spot an issue here? I have a junction table representing a many-to-many relationship. The way it is organized in my schema can be seen in the following link, and the way I am trying to query it can be seen in the attached picture.
The TLDR of the schema: templateDefinition has many colorSets, colorSets have many templateDefinition. I want to query templateDefinition to include colorSets from the junction table https://gist.github.com/Connorelsea/76f12181ec4205533bdc4329970a6f66...
No description

Applying drizzle migrations on Vercel with Hono

Hi, I'm trying to apply that migrations on the directory like this: ```typescript await migrate(drizzleDb, { migrationsFolder: "./src/databases/tenants/migrations", })...

Unable to use `push` or `studio` anymore

Really no idea what happened but all of a sudden I'm getting this messages when trying to run any of those commands ```
drizzle-kit push
...

Using drizzle-kit push only works the first time (when database is empty)

I am using drizzle with supabase. I successfully pushed my schema for the first time but when updating it with new tables it hangs down in Pulling schema from database... To solve it I have to delete all the tables or intentionally make an error somewhere in drizzle config. Is this my issue or drizzle issue? I have been seeing similar cases but with no solution yet....

many to many help

Unable to create many to many relationship with junction table
No description

Orphaned Children tables after a successful migration

I was able to bypass sqlite constraint error by using PRAGMA foreign_keys option but it left my database in a corrupted state where children tables of ticket_order are referring to the temporary and now deleted ticket_order_old table ``sql PRAGMA foreign_keys=off;--> statement-breakpoint ALTER TABLE ticket_order RENAME TO ticket_order_old`;--> statement-breakpoint...
No description

Orphaned children tables after a successful migration

I was able to bypass sqlite constraint error by using PRAGMA foreign_keys option but it left my database in a corrupted state where children tables of ticket_order are referring to the temporary and now deleted ticket_order_old table ``sql PRAGMA foreign_keys=off;--> statement-breakpoint ALTER TABLE ticket_order RENAME TO ticket_order_old`;--> statement-breakpoint...

How to achieve a returning insert with relations

Hey so I noticed this is not currently possible, any advice on how I might be able to do this with the sql api? https://github.com/drizzle-team/drizzle-orm/issues/2325...

custom datatypes

Let's say I have
features: text().array().notNull().default(sql`ARRAY[]::text[]`),
features: text().array().notNull().default(sql`ARRAY[]::text[]`),
...

planetscale mysql serial col error

Any idea why using serial() within a column def throws an error?
No description

DefaultPostgresSchema?

Object literal may only specify known properties, and 'users' does not exist in type 'DefaultPostgresSchema'.ts(2353) âš  Error (TS2353) | Object literal may only specify known properties, and users does not exist in type . (property) users: PgTableWithColumns<{...