Skip to content

Revert a migration without losing data

Learn how PlanetScale lets you revert changes to your database after a migration with no downtime and zero data loss.

Revert a migration without losing data

Bad migrations happen every day and data loss can be devastating. PlanetScale’s new schema revert feature gives you the power to revert changes after a schema migration with no downtime and zero data loss.

What is it?

Have you ever made a schema change, like changing a column’s data type or dropping a table, that broke your production application causing unplanned downtime, or even worse, a full-scale outage? And once it was live, you immediately wished you could go back in time, without losing any data that was added during the broken period?

Your wish has come true. PlanetScale’s new schema revert feature allows you to revert a migration with zero data loss.

This feature enables something never possible before: The ability to revert your database’s schema changes in less than a minute with the press of a button with no downtime or data loss. Previously, if you dropped the wrong index, running a new migration might take you a few hours to fix. Even worse, if you dropped the wrong column or table and had to restore from a backup, it would take days or weeks to roll out. And what happens to your data and your application while it is being fixed?

Schema reverts open the door to a new level of velocity and power for your engineering team. Along with existing PlanetScale features such as Database Branching and Deploy Requests, you can make changes (and fix changes) in your database faster and safer than before. It not only saves you time, but it makes schema changes less scary because you can treat your database like you treat your code. Unless you built custom in-house tooling for your database, these workflows have not been possible before.

How does it work?

After you have completed a deploy request, you will be able to revert to a clean state of the database before the schema changes. This includes any data that may have been removed in the deploy request. Any database enrolled in the limited beta will see a “Revert changes” button available on the relevant deploy request page for 30 minutes after the changes have been deployed. Once the “Revert changes” button is selected, it is deployed immediately.

For example, if you remove a column and its associated data in a deploy request, and then revert it, your column and its associated data will appear again in seconds.

This is possible because of VReplication in Vitess, the database clustering and management system that powers PlanetScale databases alongside MySQL. Vitess’ VReplication also powers features like Database Imports. VReplication uses a lossless sync in the background between valid states of the database. It copies data from the source to the destination table in a consistent fashion. VReplication’s implementation is unique because it allows us to go down to the MySQL transaction level, ensuring no data is lost and that your database schema returns to its previous state before the schema change. All in just seconds.

For a more in-depth look at how this works, take a look at the Behind the scenes: how schema reverts work blog post.

Want to see it in action?

Sign up for the limited beta to test it out yourself! Sign up or log into PlanetScale and opt into the limited beta in your database’s Settings tab. In the Beta features section, select “Enroll this database in the schema revert limited beta.” Once you create a database branch with changes to your schema, deploy the deploy request, and then revert!

For more information, check out our Deploy requests – Revert a schema change documentation.