Prisma to Drizzle migration complete! 🎉 Our journey and lessons learned #3146
Replies: 8 comments
-
This was a great read! Thanks for sharing!
You got some talented people!
Some people have suggested that Drizzle is more verbose. This is very interesting. |
Beta Was this translation helpful? Give feedback.
-
@Angelelz Thank you for the kind words! I took another peek at the before and after regarding the repository code. The method chaining in Drizzle versus object in Prisma contributes to the line drop. In all fairness, it's mostly syntax. Nevertheless, we have skinnier files as a result. 😊 |
Beta Was this translation helpful? Give feedback.
-
@oureboros when you say that you run one test at a time, did you say that the truncate approach doesn't work when running multiple tests files at once? (Something like running two tests files like login.test.ts and logout.test.ts). |
Beta Was this translation helpful? Give feedback.
-
@gabbrieu In the case of using Jest for integration tests, running one test at a time (e.g., |
Beta Was this translation helpful? Give feedback.
-
@oureboros oh i see. I'm not using Jest, I'm using the native bun implementation to test. I'll try to switch to jest to see if it works for me. My problem is that if I end the database connection in one test it is ending all connections in the other tests, even though i start the connection in the tests itself |
Beta Was this translation helpful? Give feedback.
-
I created an issue for this a while ago: #1196 |
Beta Was this translation helpful? Give feedback.
-
Hi, @oureboros, one question: When you moved the updatedAt behavior to domain, how exactly did you do it? |
Beta Was this translation helpful? Give feedback.
-
Incase you missed it Drizzle now supports to .$onUpdate(() => new Date()) function for your schema |
Beta Was this translation helpful? Give feedback.
-
Hi!
We recently migrated from Prisma to Drizzle and wanted to provide a quick write-up on our experience in case it helps anyone else. Your GitHub issues were super useful, which I reference below for other people coming across similar questions/problems.
Below was the strategy:
@todo
that required action. Most of the changes to the schema afterward were to account for the Prisma magic that went away. The biggest effort was having to manually create all of the "relations" by hand to use the "include" relations: https://orm.drizzle.team/docs/rqb#include-relationsHere are the problems as I encountered them and the solutions:
yarn drizzle:push && yarn jest
), and then in the teardown, iterating over the tables and truncating (refactored from Prisma):updatedAt
) - [FEATURE]: Prisma'supdatedAt
behavior.onUpdate
API suggestion #956include
on create and update. I generically relied on this, allowing for side-loading resources on creation.db.$executeRaw
RETURNING table.id
and look at result lengthonConflict
with composite primary keys #1029unstable_dev
, about a quarter of the tests failed with the following error: "Cannot perform I/O on behalf of a different request. I/O objects (such as streams, request/response bodies, and others) created in the context of one request handler cannot be accessed from a different request's handler. This is a limitation of Cloudflare Workers which allows us to improve overall performance."Why the migration?
I went to implement E2E testing of Cloudflare workers locally (using
unstable_dev
) and ran into an issue where only@prisma/client/edge
can be used in a Cloudflare worker but requires using Prisma data proxy. After burning a lot of time and looking for local workarounds, it was the last straw, and here I am. There are other complaints, namely their documentation, but the inability to perform local E2E tests is unacceptable. The management team wanted to proceed with Prisma with bandaids, and I'm glad I opted for the late nights instead.How long and how much effort?
Comments/Feedback
node_compat
to Wrangler to use Drizzle. This issue is indeed more withpostgres.js
.eq
, etc.A bit about our project:
Thanks for all the hard work; Drizzle is awesome and community-friendly!✌🏻
Beta Was this translation helpful? Give feedback.
All reactions