Drizzle Team

DT

Drizzle Team

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

Join

Dropping unique constraint cant push to db

I have this key here nftCollectionIdKey: unique("Pool_nftCollectionId_key").on( table.nftCollectionAddress ), ...

I'm getting circular dependency problems because each table relation is declared from the table file

Is there a better way to declare relations ? What I ended up doing was declaring all my relations in a separate file "relations.ts"....

How do I import a type?

This might be something I'm just totally overlooking, but I'm used to prisma where you can just import any schema you've defined as a type. For example, if I have a table posts, I'd expecect to be able to import a Post type to be used in one of my child components. Is this possible with Drizzle? Or have you all found it to be unnecessary...

When pushing migrations to Supabase, it skips saying the schema "drizzle" already exists.

When I update my schema and try to push the migration to Supabase, I get the following error. How can I move forward with pushing it as opposed to having it skip? I guess part of the issue is I don't understand how migrations really work so not sure what this error is telling me is wrong. In my database, I already have 2 entries in a table called __drizzle_migrations under the drizzle schema that was auto-created by drizzle-kit when migrating the first few times ```js...

0 tables fetched when introspecting a postgres database

I granted all permissions to a drizzle user like this
GRANT ALL PRIVILEGES ON SCHEMA public TO prisma;
GRANT ALL PRIVILEGES ON SCHEMA public TO prisma;
But when I try to introspect with this connection string...

PostgreSQL migration issue in AWS RDS with Drizzle ORM: 'no pg_hba.conf entry for host' error

I've been using drizzle for a new project over the past few weeks, and it has provided a great developer experience. Now, it's time to bring the app to production. However, I'm currently facing an issue with the migrations. The app is deployed in AWS ECS and connects to a PostgreSQL database in AWS RDS. I have provided the necessary IAM policies in the ECS task role to access the RDS instance. The connection is established but after that when I execute the migrate function, I'm encountering an error that I didn't experience while running locally. ```...

Date condition on where function

Hello everyone, so I have this schema of accounts and I want to get all the data from the current date ``` export const accounts = mysqlTable("account", { ......

ReferenceError: Cannot access 'addon' before initialization

This is one of the files in ./schema/ ```ts import { integer, primaryKey,...

DISTINCT ON syntax error with multiple columns in select

Hi! Thought I'd bring up this issue I opened here: https://github.com/drizzle-team/drizzle-orm/issues/963 Let me know if we think this is a valid issue or just a pure user error. Happy to close it if I'm doing anything wrong!...

Unchanged schema, `db:push:pg` generates faulty `ALTER` statements

Schema: ``` CREATE TABLE IF NOT EXISTS "private"."users" ( "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL,...

Get `id` of inserted row

Is this the right way to get the id of an insert? It feels incredibly cumbersome for such a common pattern, so feel like I'm doing something wrong:
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
...

Column primary key not working

What am I doing wrong when defining my primary key here? column: ``` const customPrimaryKey = customType<{ data: number;...

Drizzle kit SQL error

Hi all, I'm getting this weird error when I try to push my schema changes using drizzle-kit push and I have no idea where to begin to solve it: ```bash...

Migrating prisma schema to drizzle

Hey you all, I'm currently migrating my prisma schema to drizzle. I'm using sqlite and checked out how the types of prisma transfer to sqlites types. However drizzle doesn't support numeric and decimal and I wondered which datatype I would use instead. Also what is the best way to implement prisma features like cuid() Using a library and then doing string("id").default(cuid())...

How to make an unsigned bigint column in MySQL

Hiya folks, I am trying to use lucia auth with drizzle, and it requires me to make a table with unsigned bigint, however I can't seem to find that option anywhere in the documentation or google. Can someone help me with that. Thanks a ton

Is there any way to specify onDeletes and onUpdates with drizzleORM?

I can't find anything in the docs that specifies these options for a mysql connection.

Does changing the name of a relationship have any consequence aside from having to fix any queries?

We want to change the name of a relationship and I was curious if this would cause any issues? Let’s say person had a cat relationship and I wanted to name it cats, would this be okay?...

First parameter has member 'readable' that is not a ReadableStream.

Hi, I'm trying to use Vercel (lambdas not edge) and Planetscale. On localhost it works fine, but when deploy I'm getting error. It happens with every query. Any ideas? ```Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: First parameter has member 'readable' that is not a ReadableStream.","reason":{"errorType":"TypeError","errorMessage":"First parameter has member 'readable' that is not a ReadableStream.","stack":["TypeError: First parameter has member 'readable' that is not a ReadableStream."," at assertReadableStream (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:362:19)"," at convertReadableWritablePair (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:3524:9)"," at ReadableStream.pipeThrough (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:3608:29)"," at fetchFinale (node:internal/deps/undici/undici:10965:56)"," at mainFetch (node:internal/deps/undici/undici:10857:9)"," at processTicksAndRejections (node:internal/process/task_queues:95:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: First parameter has member 'readable' that is not a ReadableStream."," at process.<anonymous> (file:///var/runtime/index.mjs:1186:17)"," at process.emit (node:events:525:35)"," at process.emit (/var/task/node_modules/source-map-support/source-map-support.js:516:21)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at processTicksAndRejections (node:internal/process/task_queues:96:32)"]}...

onDuplicateKeyUpdate ???

i don't suppose anyone knows how to actually use this method? zero documentation on it and the planetscale dbClient only recognises this method after the values function. There is no "onConflictDoUpdate" or "onConflictDoNothing"....i just want it so if there is an item with the same slug, ignore the query... ```ts export async function seed(client: DbClient) { await client...

data migration on a D1 database

hello. i need to do a data migration in a D1 database and need to update the data in primary keys. what approach would you recommend? thanks in advance.