DT
Drizzle Teamptrxyz
Migrating from Prisma Schema
I want to migrate away from Prisma, but I can't seem to find a good way to get the schema right:
- Drizzle's introspect feature somehow generates garbage with VARCHARs deafult values, I saw that this seems to be a known issue on GitHub, so I suppose there is nothign I can do about that?
- Then, while 1:1 relations seem to be covered, I can't get it to generate any (many:many) relations. How is that done by Drizzle? Does it use some kind of heuristics to detect relations? Our company's model has roughly 100 tables and for now we used Prisma to handle it, so we have a prisma schema in case that helps anything, but managing all relations manually is probably error prone and a bit of a problem.
- Kysely has a nice generator to generate types from a Prisma schema. Can Drizzle also do that?
Luxaritas•246d ago
Most likely, the ideal option would be drizzle’s introspection. As you pointed out
1) sounds like a bug, unfortunately
2) Keep in mind on a DB level there is no such thing as a many to many, and so neither does Drizzle schemas model that. Prisma under the hood will generate intermediate tables for you. Those intermediate tables and their relations should be picked up by Drizzle as long as they’re actually foreign keys
3) I have a Prisma generator I wrote that I’m using in a production project (right now, we’re running Prisma and Drizzle side by side). It’s really tailored for our use case right now, and my plan has been to get it cleaned up and more widely available but just haven’t had the time. If that’s important for you let me know and we can try and work something out. That said, be aware that there’s a number of limitations - eg, Prisma doesn’t expose native DB types you specify, and drizzle uses different aliases of column names in some cases, so the generator can’t create a 1:1 mapping of the exact types in your DB (but good enough to create a working query builder)
ptrxyz•246d ago
So you ended up writing your own converter that reads a prisma schema and then creates the relations based on that?
Luxaritas•246d ago
It’s a Prisma generator that outputs a drizzle schema, which is analogous to what the Kysely one does
ptrxyz•245d ago
I also ended up writing my own generator for now. However we are still in evaluation phase if drizzle works for us, so don't want to put too much effort into this and make it more generally applicable.
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
7.4KMembers
View on DiscordWant results from more Discord servers?
More Posts[HELP]: I'm trying to re-create a CTE-insert in drizzle, having some difficulties```sql
with cart_products as (
select * from cart_product where cart_id = ${cartId}
)
insert into Add drizzle-kit check as a pre-commit hookIs there a way to add drizzle-kit check as a pre-commit hook with husky that would actually prevent Planetscale swapped the order of Primary Key RelationHey, running into this weird issue when using Drizzle push on a staging branch of Planetscale, tryinPostgres functions in the ORM?Hello everyone, I'm learning typescript and SQL (with drizzle) and I'm trying to make an api endpoinInferModelFromColumns with columns defined with sql``Let's say I have a select list that looks like this
```ts
const defaultBookFields = {
id: books.Issue with drizzle-zod?Schema
```
export const testinArray = pgTable("testing_array", {
id: varchar("id", { length: 14 Optional One-to-One RelationCurrently it's possible to define only a One-to-One relation (https://orm.drizzle.team/docs/rqb#one-Having Issues Pushing Database SchemaHi I am getting this issue whenever I am trying to push the database schema. Any help would be greatmigration failedcode:
```js
const migrationClient = postgres("postgresql://jer:admin@localhost:5432/test", { max: 1TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')I am attempting to run db push, but I am getting this error above^^
does anyone know what might be