Drizzle Team

DT

Drizzle Team

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

Join

Schema review

Is there anything that can be optimized about the schema below:

CTE / WITH + alias

Playground: https://drizzle.run/zb932yr9sv2w1nzn916wzvdt How can i generate the same SQL code (left join "bar" as cte1) without``js sql${cte} as cte1`...

Can't find ``all`` option on join

In this example: https://orm.drizzle.team/docs/joins#many-to-one-example They use a .all(); at the end to get more than 1 joined element. I'm trying a very similar thing and there is no all function: ```js let orders = await database...

Search on user's fullname

I have a user's table that stores first, middle and last names, I want to create another field named search that can be automatically calculated from these three fields. I saw something on the docs about something called full-text search, but I don't think that is is needed for my case, I just to be able to find users based on any part of their name provided. I am not a postgres expert, so I will appreciate any advice if I am wrong....

Drizzle is not working properly and not creating tables

drizzle studio is not working properly and it only take one table it is not accepting the new tables which i am creating
No description

securityInvoker

Hello, while generating the schema in version "drizzle-kit": "^0.30.4", the securityInvoker field comes as string while the (documentation)[https://orm.drizzle.team/docs/rls#rls-on-views] says its a bool . Is there a fix for this?...
No description

What's the hash in the __drizzle_migrations table used for?

I was wondering what the hash in the migration table is used for? I was playing around a bit to see what happens when I did a drizzle-kit push and manually update the migration table.. It seems to work by just updating the created_at timestamps to the when timestamp in the journal. Is it safe to do this? What is the hash used for and when could this create problems?...

No Such Index w/ .unqiue() Constrain

Hello! I am running into a issue using sqlite / turso where when applying a .unique() constraint and running db:push it is giving the following error: ```...

Self join breaks return type

Same issue as https://discord.com/channels/1043890932593987624/1286374226667896914 The return type of the query is never[]. If I remove the left join, things return to normal. The query works as expected, the result is just never[]....
No description

multiple schema files

Hi im a bit confused on how to use multiple schemas. When i use mutiple files, db._.fullSchema retuns a emty object. this is my drizzle config: ```ts import "dotenv/config"; import { defineConfig } from "drizzle-kit";...
No description

unique constraint does not seem to be applying as intended.

``ts export const PlayerDiscordCacheTable = pgTable( tal_player_discord_cache_table`, { id: uuid().defaultRandom().primaryKey(),...

Using magic SQL operator with 2 SQL dbs

Hi folks, In my project I need to connect to both separate mysql and postgres databases. I am able to successfully do so and create database objects but trying to execute raw SQL is not working currently using the magic SQL wrapper syntax. Typescript is confused because it does not know how to assign the types for sql as it tries to assign them from mysql and pg types...

ExpoSQLite migration immediately fails... How to solve (without deleting migration files)?

I am trying to run my first update migrations after my first DB change (after initial migration to create initial migration from schema)... But the migration immediatey fails: ```...

Is This SQL Query Efficient? Seeking Advice!

I'm quite beginner to SQL and Drizzle, and I wrote a query, but I have no idea how efficient it is. I don’t even know what to look for. I asked AI, and according to it, my query is inefficient because it contains a subquery that runs for every row in the database: where: or( eq(topping_categories.isGlobal, true), inArray(...
No description

Pkey violates unique constraint after Seed

After i add data to the DB with some data and i try to do an insert, i get the error: duplicate key value violates unique constraint "users_pkey". I can get around it by
await db.execute(sql.raw(
`ALTER SEQUENCE users_id_seq RESTART WITH ${Math.max(...users.map(u => u.id)) + 1}`
));
await db.execute(sql.raw(
`ALTER SEQUENCE users_id_seq RESTART WITH ${Math.max(...users.map(u => u.id)) + 1}`
));
but i was wondering if there was something im doing wrong when inserting? ...

Error: There are multiple relations between "__public__.*" and "*". Please specify relation name

I got this error and originally it was a legitimate error (which i fixed) however drizzle studio is still complaining about it.

The equivalent of connectOrCreate from Prisma

I'm still new to SQL and Drizzle, so I'll try to describe this as best I can. With Prisma you have the connectOrCreate, if you're trying to create a relation that may or may not exist already. Is there anything equivalent in drizzle? So far I haven't been able to figure it out....

Version required mkcert.

when i run studio i get this error This version of drizzle-kit requires newer version of drizzle-orm Please update drizzle-orm package to the latest version 👍 ...
No description

Checking whether devs forgot to generate migrations

Hey there! I'm looking to create a CI test, checking whether the developer has forgotten to generate migrations (it happens sometimes that someone pushes commits updating the drizzle schemas, but they forget to generate the corresponding migrations). My current approach is to run a drizzle-kit generate from the CI, and see whether some files were generated in the migration folder. It works in most cases, but if the migration generation asks some questions (e.g column renamed), my CI job just skips generating migrations. As a result it considers that no migration was forgotten, which is wrong. I'm wondering whether there are better approaches I can take? Maybe some Drizzle API allows checking for migrations, without requiring interaction? Thanks for the great lib, and for any help you can provide!...