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?
4 Replies
Luxaritas
Luxaritas15mo 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
ptrxyzOP15mo ago
So you ended up writing your own converter that reads a prisma schema and then creates the relations based on that?
Luxaritas
Luxaritas15mo ago
It’s a Prisma generator that outputs a drizzle schema, which is analogous to what the Kysely one does
ptrxyz
ptrxyzOP15mo 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.
Want results from more Discord servers?
Add your server