You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by MichaelHindley, Sebastián Balay, Majid Amiri, Tobias Diez, Andrés Godínez, Tino Koch, Deeptesh Chagan, JongBeom Kim, Serry Park, Dmitrii Kartashev and 24 more
Reacted by Dmitrii Kartashev, jagged3dge, Joshua, Daan H., Shai Reznik and Daniel Haupt
@Jolg42 anything to mention here is that reset drops all internal postgres tables when using something like supabase, this causes issues and essentially breaks the database.
We really need a nice way to reset the state of the DB to just the tables managed by prisma.
@Jolg42 anything to mention here is that reset drops all internal postgres tables when using something like supabase, this causes issues and essentially breaks the database.
Can you please create a new bug report issue about this? We want to look into that separately and figure out if there is a more direct way to fix this. reset should never destroy things. Thanks.
Any progress on this? I would really like to be able to reset my Postgres database between e2e test suites, but right now this means that my NextJS server errors with cache lookup failed for type 27622 (or some other number). When I restart the server, this error goes away - the first test suite always succeeds.
I believe the reason is that db push --force-reset also drops all tables and enums, and generates a new enum with the same name, but a different type number. But the server is of course not notified of this, so it's still using some internal cache with the old enum definitions.
In an ideal situation, I would like to
On the start of the test suite, run the migrations (I believe prisma migrate dev --force is suitable for this);
Before each test suite, empty the database and apply seed data, but do keep all tables, enums and sequences.
importprisma,{Prisma}from'@/lib/prisma'typeTableNames=Array<{tablename: string}>consttableNamesSQL=Prisma.sql` SELECT tablename FROM pg_tables WHERE schemaname='public'`typeSequences=Array<{relname: string}>constsequencesSQL=Prisma.sql` SELECT c.relname FROM pg_class AS c JOIN pg_namespace AS n ON c.relnamespace = n.oid WHERE c.relkind='S' AND n.nspname='public';`// waiting for [Feature request: `prisma db truncate` · Issue #5596 · prisma/prisma](https://github.com/prisma/prisma/issues/5596)consttruncate=async()=>{// truncate all the tablesconsttablenames=awaitprisma.$queryRaw<TableNames>(tableNamesSQL)consttables=tablenames.map(({ tablename })=>tablename).filter((name)=>name!=='_prisma_migrations').map((name)=>`"public"."${name}"`).join(', ')awaitprisma.$executeRawUnsafe(`TRUNCATE TABLE ${tables} CASCADE;`)// reset all the sequences (ids)constsequences=awaitprisma.$queryRaw<Sequences>(sequencesSQL)for(const{ relname }ofsequences){awaitprisma.$executeRawUnsafe(`ALTER SEQUENCE "public"."${relname}" RESTART WITH 1;`)}}afterEach(async()=>{awaittruncate()})
Activity
ydennisy commentedon Feb 23, 2022
@Jolg42 anything to mention here is that
resetdrops all internal postgres tables when using something like supabase, this causes issues and essentially breaks the database.We really need a nice way to reset the state of the DB to just the tables managed by prisma.
janpio commentedon Feb 23, 2022
Can you please create a new bug report issue about this? We want to look into that separately and figure out if there is a more direct way to fix this.
resetshould never destroy things. Thanks.tsongas commentedon Jul 18, 2022
Yes please!
rubenhelsloot commentedon Feb 24, 2023
Any progress on this? I would really like to be able to reset my Postgres database between e2e test suites, but right now this means that my NextJS server errors with
cache lookup failed for type 27622(or some other number). When I restart the server, this error goes away - the first test suite always succeeds.I believe the reason is that
db push --force-resetalso drops all tables and enums, and generates a new enum with the same name, but a different type number. But the server is of course not notified of this, so it's still using some internal cache with the old enum definitions.In an ideal situation, I would like to
prisma migrate dev --forceis suitable for this);foloinfo commentedon Oct 6, 2023
I was trying to figure out how to smoothly run tests while resetting the data between each spec.
I found this CRUD (Reference) | Prisma Docs and Easy workflow to reset all data · Issue #742 · prisma/prisma helpful, but needed to change slightly since the API has changed.
This is my current setup. I want a function like
await prisma.truncate(),prisma db drop. Such utilities greatly enhance the developer experience.setupAfterEnv.ts
jest.config.js (nextjs)
package.json
When running the test for the first time, I need to create the db with
yarn db:migrate:testjust likerails db:migrate RAILS_ENV=test