How to squash migrations in Prisma
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Squashing migrations in Prisma helps to optimize your migration history by combining multiple migration files into one. This is particularly useful for projects with a large number of migrations, making the history cleaner and easier to manage.
First, backup your database. This step is critical. Don’t skip it.
# For PostgreSQL
pg_dump dbname > backup.sql
# For MySQL
mysqldump -u username -p dbname > backup.sql
Delete the migrations folder in your prisma directory.
rm -r prisma/migrations
Run prisma migrate dev to create a new migration that represents the squashed schema.
prisma migrate dev --name squashed_migration
This will create a new migrations folder containing a single migration that represents your current schema.
Apply the new migration to a fresh database to ensure it works as expected. Make sure to only run this in development since it will wipe your database.
prisma migrate reset
Commit the new migrations folder and the updated schema.prisma to your version control system.
git add -A
git commit -m "Squashed migrations"
For Prisma workflows, Basedash works as an AI-native BI layer over your database so engineers and non-technical teammates can inspect migration outcomes, ask follow-up questions, and track changes in shared dashboards.
migrations folder.And there you have it: your migrations are now squashed and your project is cleaner for it.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.