question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a `prisma.$reset()` function as shortcut to running `prisma migrate reset`

See original GitHub issue

Problem

prisma migrate reset is used heavily for testing. I want a prisma.$reset() function added to prisma client as super easy shortcut to reset the database.

Suggested solution

I’ve added this to our Blitz adapter and it’s super nice in Jest tests:

beforeEach(async () => {
  await db.$reset()
})

Optionally this command could be disabled/fail if process.env.NODE_ENV === 'production'

Alternatives

None

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:51
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
flybayercommented, Mar 8, 2021

As a workaround, you can copy the code we use in Blitz for this: https://github.com/blitz-js/blitz/blob/canary/packages/core/src/prisma-utils.ts

Which you can then use like this:

import {enhancePrisma} from "./enhancePrisma"
import {PrismaClient} from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)

export * from "@prisma/client"
export default new EnhancedPrisma()
5reactions
yue4ucommented, Mar 3, 2022

FYI I’m migrating from sequelize to prisma and at the moment performance using transaction + executeRaw method by @rsaryev (https://gist.github.com/rsaryev/65884be2d8992552e9a603fefabaecb3) is close to sequelize’s and much more faster (10s per reset in my jest setup) than spawning migrate reset cli each time .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Migrate | Database, Schema, SQL Migration Tool
Prisma Migrate is a database migration tool available via the Prisma CLI that integrates with Prisma schema for data modeling.
Read more >
Prisma Migrate in development and production
Reset the development database. You can also reset the database yourself to undo manual changes or db push experiments by running: $npx prisma...
Read more >
Prisma CLI Command Reference
migrate reset. For use in development environments only. This command deletes and recreates the database, or performs a 'soft reset' by removing all...
Read more >
Developing with Prisma Migrate
You should expect to reset your database in a development environment - for example, if you regularly switch between branches that have different...
Read more >
Migration troubleshooting in development - Prisma
If Prisma Migrate detects a migration history conflict when you run prisma migrate dev , the CLI will ask to reset the database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found