Drizzle Team

DT

Drizzle Team

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

Join

SQLite migrations are not being applied

First time using SQLite and drizzleORM, so forgive me if this is a stupid question. I've been trying to set this up for an hour now. I have installed drizzleORM and drizzle-kit, I've added the setup from the docs and I have ran my first migration with drizzle-kit generate:sqlite. I have a db file in my root and folder with the migration that creates a users table. I get an error when I try query the users table, saying it does not exist....

Question: Wouldnt it make sense for value to be automatically notNull if you set a default

Right now you would need to use notNull().default(true), is there a reason for it be still nullable with just default?

Code generated value

I'm using SQLite. How can I create a custom type with an auto-generated value which is generated in code and not the database? I managed to get it to work, but I have to pass a blank value for the field whenever creating records otherwise I get a type error, and I'm having trouble finding the right combination of options. ```ts import {customType, sqliteTable } from "drizzle-orm/sqlite-core"; import { createId } from "@paralleldrive/cuid2";...

Randomly stopped being able to generate migrations (MySQL)

Hey! Been trying things out the past day and everything was going great - until I deleted my migrations folder, attempted to re-generate migrations, and was met with 0 tables 🤣 I've killed-off all of my schema, except for one simple table, and ran generate:mysql with DEBUG; ```bash...

BUG: Postgres migration script generates a few syntax errors

Context: I was running migrations with drizzle-kit's migration function from node-postgres , and kept getting a lot of errors. I had to make the following changes to the SQL script: 1. Add double quotes around table, index, and other field names 2. Array fields with default values just never generated the right code. So I had to manually add the default value in. ...

uuid's being inferred as strings

When I use InferModel on a table that has a uuid type, I see that the column gets inferred as a string instead of as a uuid type. Seems like the migrations are correctly using the native postgres uuid type, so confused why it's not being returned as a UUID

Any easy way to create a typescript ENUM type from pgEnum?

Prisma used to auto-gen all the enum types as well which are heavily used in our application.

Plans to add array related support for Postgres?

+ features to append an object to an array field in postgres?

Migrating from Prisma

Hi, I have an existing project already in production built using prisma and postgres (supabase). I am planning to go serverless and hence planning to migrate to drizzle + PlanetScale. Here is how I am planning it: 1. Use Prisma to generate the entire schema structure in MySQL (Planetscale) 2. Use Drizzlekit to introspect and generate types. 3. Use Drizzle ORM for querying....

Cannot read properties of undefined (reading '0')

What is the expected behavior when using get() when there would be no matching results for a given select query? Does it return null or would this be an error? At present it's giving an error. I'm new to discord, but I guess I expected it to return a null. For example, the following query works and returns an empty array:
db.select().from(users).where(eq(users.email, email)).all();
db.select().from(users).where(eq(users.email, email)).all();
whereas changing all() to get() results in error trying to access first element of an empty array (drizzle-orm/utils.js:40:37):...

Is it recommended to create a SQL transaction every time we try to create a foreign relationship?

prisma used to wrap every foreign upsert (2 entities) within a transaction to guarantee that both rows are created or the changes are rolled back in case of a failure. Is there a way in drizzle to achieve the same? or is it better to individually create the entities?

Doesn't drizzle-kit generate:pg work yet when schema imports from esm package?

```
drizzle-kit generate:pg --out src/db/migrations --schema src/db/schemas
drizzle-kit: v0.17.0 drizzle-orm: v0.23.1...

Is there `.returning()` in insert statement in MySQL like SQLite?

There is .returning() insert statement in SQLite but MySQL not. how do I .returning() in insert statement in MySQL?...

Getting results in document form rather than record

Hi, new to drizzle but liking it so far. Is there away to get the results in more of a 'document' structure? For example, I'd like to get {id: 1, user: "joe", posts: [{id : 1, title: "my first post"},{id : 2, title: "my second post"}]} rather than in record form [{id: 1, user: "joe", post: {id : 1, title: "my first post"}}, ...}]. I'm doing something like select({id ... post: {id: posts.id, title, posts.title}}). Thanks.

Unable to upgrade migrations if there are ones that do not change state but manipulate data

Hi! I have 0.16.x migrations. At some point, I needed to manipulate the data without changing the db structure, so I just made a copy of the latest migration, assigned new ID in snapshot.json and added my sql code. It worked fine, but when I moved to drizzle-kit@0.17.0 and tried to upgrade the migrations, I got the following errors: ``` Everything's fine :dog::fire: {...

require() of ES Module is not supported planetscale serverless + sveltekit

Hi, I am getting this error when I user planetscale serverless with drizzle orm ``` require() of ES Module D:\svelte-edge\node_modules@planetscale\database\dist\index.js from D:\svelte-edge\node_modules\drizzle-orm\planetscale-serverless\session.js not supported. Instead change the require of index.js in D:\svelte-edge\node_modules\drizzle-orm\planetscale-serverless\session.js to a dynamic import() which is available in all CommonJS modules....

Applying migrations with drizzle-orm/pg-core

How would I apply all the migrations that have not yet been applied? I couldn't find any information in the docs...