Can prisma generate rollback sql? Prisma migrate d...
# orm-help
t
Can prisma generate rollback sql? Prisma migrate dev reset all migration if having conflict migration sql which not existed when finally run migration. If we fails migration for dev and want to re-migrate without dropping table data, currently possible solution is to run manually sql?
βœ… 1
i
t
It’s exactly what I wanted. Thanks.
πŸ‘ 1
I realized rollback my dev database to point I want to do so, and re-migrate. For someone in same situations, I wrote what I did.
Copy code
1. create database for shadow_database
2. remove migration files temporally you want to rollback
3. run `prisma migrate diff --from-schema-datamodel prisma/schema.prisma --to-migrations prisma/migrations --shadow-database-url "${SHADOW_DATABASE_URL}" --script > down.sql`
4. run `prisma db execute --file ./down.sql --schema prisma/schema.prisma`
5. delete records from _prisma_migrations you rolled back
prisma migrate dev
detect conflict and intend to reset migration even if migrate records have marked as applied or rollbacked column, so you need delete migration records in development. If you need to keep migration files for production already applied, restore remove migration files and applied.
Copy code
prisma resolve (--rolled-back or --applied)