/supabase-tutorials

How to roll back a migration in Supabase?

Learn how to roll back a migration in Supabase with our step-by-step guide. Manually reverse changes, verify your schema, and update your migration records.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to roll back a migration in Supabase?

 

Step 1: Understanding Migrations in Supabase

 

Migrations in Supabase are a way to define and apply database schema changes over time. They are important for version control of the database schema and facilitate teamwork in collaborating environments. Migrations allow you to apply incremental changes to your database schema.

 

Step 2: Checking Existing Migrations

 

Before rolling back a migration, it's essential to know which migrations have already been applied to your database. You can use the Supabase CLI to list these migrations. Navigate to your Supabase project directory in your terminal or command prompt and execute:


supabase db reset

This will print a list of all migrations that have been applied. Take note of the migration you intend to roll back.

 

Step 3: Identifying the Target Migration

 

Decide which migration you would like to roll back. Typically, migrations are named using a timestamp and a descriptive name, such as 20230101123000_create_users_table.sql. Identify the migration you wish to revert to or the precise one you want to roll back.

 

Step 4: Rolling Back a Migration

 

To roll back a migration in Supabase, you'll use a custom SQL script to undo the changes made by the migration you want to reverse. Unfortunately, Supabase currently does not have a direct CLI command for rolling back a migration automatically. You'll need to manually execute SQL that reverses the changes.

For example, if a migration added a new table, manually create a new SQL file to drop that table:

rollback_create_users_table.sql


DROP TABLE IF EXISTS users;

Execute this SQL using the command:


supabase db remote commit -f rollback_create_users\_table.sql

 

Step 5: Verifying the Rollback

 

After running the rollback SQL script, it's important to verify that the database schema is in the expected state. You can check the schema using the Supabase dashboard or execute SQL queries to confirm the absence of the changes made by the migration.

 

Step 6: Tracking Rollback Changes

 

Once you've confirmed that the rollback is successful, document this change appropriately. This documentation helps keep track of the changes in your migration history and assists other team members who may be pulling the latest changes. You might add notes in your version control system referencing the manual rollback SQL file.

 

Step 7: Updating Migration Records

 

It's good practice to update your migration records or logs to indicate that a particular migration was rolled back and no longer in effect. This step helps maintain clear insight into the current state of the database schema.

 

Step 8: Testing the Updated Schema

 

Finally, test your application to ensure that rolling back the migration has not caused any unexpected issues. Ensure that the application functions as expected with the updated schema and that no reliant features break due to the rollback.

 

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022