How to squash migrations in Prisma
October 21, 2023
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.
Pre-requisites
- Prisma CLI installed
- A Prisma project with existing migrations
Steps to Squash Migrations
Backup Database
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 Migrations Folder
Delete the migrations
folder in your prisma
directory.
rm -r prisma/migrations
Generate Squashed Migration
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.
Test The New Migration
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 Changes
Commit the new migrations
folder and the updated schema.prisma
to your version control system.
git add -A git commit -m "Squashed migrations"
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Caveats and Warnings
- History Mismatch: Squashing migrations will cause a history mismatch in environments where the migrations have been applied. Coordinate with your team to apply the squashed migration in all environments. This can be a problem if your migrations are used in systems that you don’t control. This is something that we have to consider at Basedash since we offer self-hosting.
- Data Loss: The
prisma migrate reset
command used for testing will wipe your database. Make sure you have a backup.
Summary
- Backup your database.
- Delete the old
migrations
folder. - Generate a new, squashed migration.
- Test the new migration.
- Commit your changes.
And there you have it: your migrations are now squashed and your project is cleaner for it.
TOC
October 21, 2023
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.
Pre-requisites
- Prisma CLI installed
- A Prisma project with existing migrations
Steps to Squash Migrations
Backup Database
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 Migrations Folder
Delete the migrations
folder in your prisma
directory.
rm -r prisma/migrations
Generate Squashed Migration
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.
Test The New Migration
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 Changes
Commit the new migrations
folder and the updated schema.prisma
to your version control system.
git add -A git commit -m "Squashed migrations"
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Caveats and Warnings
- History Mismatch: Squashing migrations will cause a history mismatch in environments where the migrations have been applied. Coordinate with your team to apply the squashed migration in all environments. This can be a problem if your migrations are used in systems that you don’t control. This is something that we have to consider at Basedash since we offer self-hosting.
- Data Loss: The
prisma migrate reset
command used for testing will wipe your database. Make sure you have a backup.
Summary
- Backup your database.
- Delete the old
migrations
folder. - Generate a new, squashed migration.
- Test the new migration.
- Commit your changes.
And there you have it: your migrations are now squashed and your project is cleaner for it.
October 21, 2023
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.
Pre-requisites
- Prisma CLI installed
- A Prisma project with existing migrations
Steps to Squash Migrations
Backup Database
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 Migrations Folder
Delete the migrations
folder in your prisma
directory.
rm -r prisma/migrations
Generate Squashed Migration
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.
Test The New Migration
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 Changes
Commit the new migrations
folder and the updated schema.prisma
to your version control system.
git add -A git commit -m "Squashed migrations"
You could ship faster.
Imagine the time you'd save if you never had to build another internal tool, write a SQL report, or manage another admin panel again. Basedash is built by internal tool builders, for internal tool builders. Our mission is to change the way developers work, so you can focus on building your product.
Caveats and Warnings
- History Mismatch: Squashing migrations will cause a history mismatch in environments where the migrations have been applied. Coordinate with your team to apply the squashed migration in all environments. This can be a problem if your migrations are used in systems that you don’t control. This is something that we have to consider at Basedash since we offer self-hosting.
- Data Loss: The
prisma migrate reset
command used for testing will wipe your database. Make sure you have a backup.
Summary
- Backup your database.
- Delete the old
migrations
folder. - Generate a new, squashed migration.
- Test the new migration.
- Commit your changes.
And there you have it: your migrations are now squashed and your project is cleaner for it.
What is Basedash?
What is Basedash?
What is Basedash?
Basedash 🤝 Prisma
Teams that build with Prisma love using Basedash to manage and administrate their databases. It fits in your stack and allows you to understand your data like never before.
Teams that build with Prisma love using Basedash to manage and administrate their databases. It fits in your stack and allows you to understand your data like never before.
Teams that build with Prisma love using Basedash to manage and administrate their databases. It fits in your stack and allows you to understand your data like never before.
Dashboards and charts
Edit data, create records, oversee how your product is running without the need to build or manage custom software.
USER CRM
ADMIN PANEL
SQL COMPOSER WITH AI
Related posts
Related posts
Related posts
How to automate Prisma migrations in a CI/CD pipeline
Max Musing
How to implement soft deletes in Prisma
Max Musing
How to use the shadow database in Prisma
Kris Lachance
How to reset and seed a Prisma database
Max Musing
UUID vs GUID vs CUID vs NanoID: A guide to database primary keys
Max Musing
How to generate UUIDs in Prisma
Max Musing