Drizzle Team

DT

Drizzle Team

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

Join

Tightening types on successful insert to not be `object | undefined`

When doing db.insert(someTable).values(someValues).returning() what would be the preferred way to narrow the type of the return value from object | undefined if the insert is successful? I'm trying to do some seeding where I create some entries in one table and save them as variables, and then attempt to insert the IDs of those entries into another table as a foreign key that's non-nullable and TS tells me that they're potentially undefined, which is true. Since this is seeding, I know I'm clearing my DB before this, so I know the inserts will succeed and that it's not an issue if they don't) so would the best way to silence these errors just be to add ! to the objects when doing returnedObject!.id? ...

Missing Refine type after update

Seem like with a recent release of drizzle-zod, we lost an exported type (namely Refine) to satisfy types in a single place. Anyone know of a better way to do this so we don't need to repeat code? And maybe any way we can export the Refine type (seems like its BuildRefine now 🤔)? ```ts import type { Refine } from 'drizzle-zod'; import { teamsTable } from '../teams-table';...

CHECK constraints not working with drizzle-orm/pg-core

Hello, I have an issue. I can't add CHECK constraints to my table. I tried with a simple example, but it's not working. Could this be a bug? I followed the code from the documentation, but the CHECK constraints aren't being applied :'( Here is my code: https://drizzle.run/m8kdhex9yw6yqaxbywunfyj4...
Code_doc

Type Inference Issue: Missing | null on Relational Fields in Drizzle ORM

When querying a company and joining related customer data, the resulting inferred TypeScript type for the customer property does not allow for null even though no record may exist. Because of this, the type inference is overly strict. In many cases, customer can be null, especially with a left join or if the relation is optional. ``ts // Query 1: Drizzle relational query // Result type incorrectly omits | undefined or | null for customer`. const res = db.query.company.findFirst({...

foreignKey function options

```ts foreignKey({ columns: [table.orgId, table.topicName], foreignColumns: [topics.orgId, topics.name], }),...

restart increment for refNumber column starting from 1

All examples I've seen increment globally for the column. I need to restart increment from 1. how would I do that? ``` export const orderItems = pgTable( "order_items",...

Neon migrations are not running in transaction

Hello, I notice that if a migration fails half way through, what ever commands happened before are being saved? Is this a bug?

Bad Field Error

I have a view that I created that joins two table. here is my implementation : ```ts export const cartView = mysqlView("carts_and_products").as((qb) => { return qb .select({...

Do all migration files get executed in single transaction?

Lets say I generated a couple migration files due to making a few changes. When the migrations run via drizzle-kit migrate, will both of the files run in a single transaction, or could 1 file run > commit > then the second file fail? This is for Neon, if that matters....

transactions rollback

Hi there! Do Drizzle transactions automatically roll back when an unexpected error occurs?

Error: getaddrinfo ENOTFOUND ep-delicate-thunder-a58xbwga.us-east-2.aws.neon.tech

I am only able to generate the migrations npx drizzle-kit generate but not able to migrate it npx drizzle-kit migrate or npx drizzle-kit studio when I am trying to open up the drizzle studio or run migrations, I am getting this error please find attachments. don't know from where it's coming, my internet is working fine...
Solution:
Seems like a Neon issue
No description

Cannot run Studio with IndexedDB setup for PGlite

Hi everyone, I start my PGlite setup with ``` const client = new PGlite('idb://xxxx'); const db = drizzle({client});...

Relations mysql Name

I am trying to use relations in drizzle and I want to have the foreign keys setup in mysql. I currently have a setup like this but when generating migratin files (drizzle-kit) it is causing foreign key names which are too long (mysql max 64). I cannot see anyway in the docs to name the specific foreign key and it would be painful if i had to manually change the foriegn key name in every generated migration each time. ``` customerId: varchar("customer_id", { length: 36 })...

drizzle-seed

is it not possible to have column refinement within a join? ```ts await seed(db, { ...schema, ...relations }).refine((f) => ({ profile: { count: 8,...

Cannot use supabase serverless on cloudflare pages

Hey all I get this error on deployment : Error: Failed to publish your Function. Got error: Uncaught Error: No such module "node:events". This is my db setup: ``` ...

Array of Integers Referencing Another Table

Hi there, I'm working with Drizzle ORM and PostgreSQL, and I need to define a column in a table that stores an array of integers. Each integer in the array should reference the id column of an asset table. Here's what I'm trying to achieve: ...

error: relation "xxx" already exists

Hello! Every time I run a second drizzle-kit up I get the same error, on the same table every time. I need to completely wipe my database in between
error: relation "table_filters" already exists...

Variable behavior for .onConflict[X] method of .insert?

Let's say that I create an array of insert statements along the lines of db.insert(targetTable).values(targetValues) and, on a conflict, I want different behavior based on why there was a conflict. For instance, if the conflict arises due to the id field having a unique constraint that would be violated by the entry, I would want to update, like: db.insert(targetTable).values(targetValues).onConflictDoUpdate({ target: targetTable.id, set: targetValues }) ...

Database design

I'm building an app for a center 'school' for Quran teaching and memorization. I want to track students daily progress and attendees, there is also can monthly tests, each class also can choose best student of the week each week. My question is: how do I link these data to a certain year?...

How to mark migration as applied?

The title. I got a hybrid database-first and codebase-first migrations I do some changes on the database itself via db tools and later create a custom migration for those changes using drizzle. Now I need to mark it as applied. I'm struggling to figure out how to do that. I would really appreciate if anyone could help me out with this one...
Next