Manage Database Change with Data Rollback
When changing data in the database, it's advisable to have a backup of the data you plan to modify in case you need to roll back. Bytebase offers a feature called Data Rollback to assist with this. This tutorial will guide you through this process.
Preparation
-
Make sure you have Docker installed, and if you donβt have important existing Bytebase data locally, you can start over from scratch by
rm -rf ~/.bytebase/data
. -
It's an Enterprise Plan feature, you need to have a valid license to enable it. You can request a trial license key from here.
Step 1 - Start Bytebase and upgrade to Enterprise Plan
-
Copy and paste the commands to start one Bytebase via Docker.
-
Regsiter an admin account and it will be granted the
workspace admin
role automatically. -
Click the Setting icon on the top right, and then click Workspace > Subscription to upload the license.
-
Click the pen icon, select the instances you want to enable Enterprise features, and click Confirm.
Step 2 - Prepare schema bbdataarchive
Bytebase stores the backup data in a dedicated place. For Postgres, it's stored under the bbdataarchive
schema for the changing database.
-
Go to
Sample Project
, click Database > Databases on the left side, choosehr_test
, and then click Edit Schema. -
In the Schema Editor, click
...
and then click Create Schema. Fill it with the namebbdataarchive
and click Create. -
You can now see the
bbdataarchive
schema in green color. Click Preview issue. Create the issue and wait till it rolls out automatically. Now thebbdataarchive
schema is created.
Step 3 - Change Data and roll back
-
Before the change, go to SQL Editor, choose
hr_test
and double clickemployee
table, and you'll see the current data. We'll try to change thefirst_name
forGeorgi
. -
Go to
Sample Project
and Database > Databases again, choosehr_test
, and then click Change Data. -
Turn on Prior Backup on the right, input the SQL into the field, and then click Create.
-
After the issue is created and then rolled out, you can see there is an activity saying the data is backed up to a new table under the previously created
bbdataarchive
schema. -
Go to Database > Databases again, and click
hr_test
. You'll be redirected to the database page. -
Choose
bbdataarchive
schema, and you can see the backup table. -
To verify, go to SQL Editor. Choose
employee
table inhr_test
underpublic
schema, input the following SQL script and click Run, and you'll see the data is changed. -
Choose
bbdataarchive
schema, and double-click the table below. You'll see the backup data in the query result.
Noteworthy Difference
If you want to use MySQL/SQL Server/Oracle, instead of creating a bbdataarchive
schema, you should create a bbdataarchive
database to store the backup data. Check the doc for more details.