Sitemap
Israeli Tech Radar

Unleashing tech insights by Tikal’s Experts. Explore the forefront of technology with Tikal, a leading hands-on tech consultancy. Get invaluable insights based on The Israeli Tech Radar, covering advancements, emerging technologies, and industry best practices.

Prisma ORM: Are You Seriously Suggesting I Reset My Production DB?!

--

If you want to learn how to recover your DB after hitting a schema drift issue or any other scenario where Prisma threatens to erase it, you have come to the right place!

If you’re in a hurry, skip to the last section — but trust me, the journey is worth it!

The Story

I heard that Prisma is an awesome ORM for TypeScript, with lots of good reviews, talks about performance, new kid on the block, etc.

So I started a project that grew quickly, and all seemed well for a few months.

Until one day, it generated a buggy query.

We tried to extend an existing Enum type, but Prisma generated an SQL statement that altered the Enum without taking proper care of a table that was already using it. Kinda’ pulling the rug under the legs, I would say…

We didn’t catch it until it went to Production, where it was scary and also very frustrating to see the following message:

“do you want to reset your DB” message — as if anyone would be happy to…

Oh, we should have *not* modified a migration.sql file.
Naively thinking, I responded with “Let’s revert”, but NO, it was too late.

And so the Saga began…

Sidenote: Prisma can check that migration files are not tampered with by saving their checksum into the _prisma_migrations table. I tried this suggestion to workaround it, but unfortunately, it didn’t work for us. Do you have any idea why? (If yes, please comment!).

Looking online in a few different places brought us only deeper into this rabbit hole, and I was shocked to see that Prisma docs also suggested that I reset the DB. Hell, I even ran into other people complaining about it!

I asked for a little help from friends, Claude and ChatGPT, but it only got worse…

While testing this on my local machine, I ran into schema drift, along with other delightful surprises:

We ended up wasting time trying workarounds, and then I fell sick.

Y’all, when you get sick, it’s your body’s way of telling you to hit the damn brakes and stop. So I did. 🤒

going through the 5 stages of grief with a schema drift

While I was “off”, my mind couldn’t stop thinking about it, and I thought about a different approach: What if I had an existing service with a full DB and wanted to adopt Prisma? There has to be a way to remove it completely from the project and then “add it from scratch”.

Removing it should be easy: just delete the ./prisma folder and drop _prisma_migrations Table in the DB. I felt like I was onto something and couldn’t wait for the beginning of the week to try this approach (I forced myself to rest, listening to my body — remember?).

When I started working on it, I found this helpful, but still had to RTFM 🤓 and put the pieces together. I hope this will save you the time that I had to spend!

TD;LR

How to reset Prisma without resetting your DB

The comments not only explain the process but are also very important for not messing up your DB — read them thoroughly!

Disclaimer: I’m not a DBA or a Prisma expert, just an engineer who ran into a problem and found a way out. Prisma actually offers some useful tools — like squashing migrations, generating down-migrations, and marking migrations as applied — so it’s worth learning more about.

Hi, I’m a senior software engineer and a tech lead at Tikal.
Tikal is a hands-on tech consultancy partner for scaling and making a tech impact on tech companies' product development. Tikal practice, driven by the Israeli Tech Radar in the domains of Fullstack, Backend, Data & ML, DevOps, and Mobile, seamlessly integrates into development teams and boosts existing engineering capabilities.

Want to join us? shoot me an email and I’ll try my best to help!

--

--

Israeli Tech Radar
Israeli Tech Radar

Published in Israeli Tech Radar

Unleashing tech insights by Tikal’s Experts. Explore the forefront of technology with Tikal, a leading hands-on tech consultancy. Get invaluable insights based on The Israeli Tech Radar, covering advancements, emerging technologies, and industry best practices.

Nir Alfasi
Nir Alfasi

Written by Nir Alfasi

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann

Responses (2)