Deploy Schema Migration with Rollout Policy
Bytebase offers a powerful GUI for schema migration deployments. This tutorial will show you how to use Bytebase to deploy schema migrations with features like SQL Review, custom approval, time scheduling, and more.
Bytebase offers Community, Pro and Enterprise Plans. Advanced plans unlock new capabilities of deploying schema migrations and this tutorial will walk you through them progressively.
Features covered
- Level 1 - Automatic SQL Review (available in all plans)
- Level 2 - Rollout Policy (available in Pro and Enterprise)
- Level 3 - Custom Approval (available in Enterprise)
Preparation
-
Make sure your Docker is running, and start the Bytebase Docker container with the following command:
-
Bytebase is running successfully in Docker, and you can visit it via
localhost:8080
. Register an admin account and it will be granted theworkspace admin
role automatically.
Level 1: Automatic rollout with SQL review (Community Plan)
-
Within Workspace, go to Environments > Test and Environments > Prod, you'll see
Rollout policy
isautomatic
. Unless there's warning or error, rollout will be automatically executed after an issue is created.SQL Review
is enabled onProd
with a sample policy.
-
Click SQL Review Sample Policy to enter SQL Review under CI/CD section, where three rules have been activated. We'll intentionally violate the Column rule
Enforce NOT NULL constraints on columns
. -
Go to
Sample Project
from top left. Go to Database > Databases, choose bothhr_prod
andhr_test
databases to Edit Schema. Paste this command into SQL block, and Create this issue on top right: -
SQL Review will run automatically along with some other checks. You'll see a warning for the task on
Prod
. ClickProd Stage
of the pipe above for details. -
Edit the SQL statement with this:
-
Now you'll see the warning disappear and the issue rolls out automatically. Click View change to see the diff.
Level 2: Manual rollout with dedicated roles and scheduled time (Pro Plan)
With Pro Plan, you'll get two additional features:
- Manual rollout policy. You can specify multiple pre-defined roles to manually roll out the change.
- Time scheduling. You can specify a particular time to roll out the change.
-
Within Workspace, go to Environments > Prod. Choose
Manual rollout by dedicated roles
, check all but the last role. Click Update on bottom right. -
Go to
Sample Project
, enter Database > Databases to Edit Schema for both databases. Paste this command into SQL block and Create. -
Task checks runs. SQL runs on
Test
automatically but waits to run onProd
. Click Rollout to trigger directly.Or set a Rollout time.
Level 3: Manual rollout with custom approval (Enterprise Plan)
If you want the approval flow to be more dynamic based on the context like the type of SQL statements, the affected rows and etc, configure custom approval flow.
Within Workspace, go to Instances and choose both instances to Assign License. Without doing this, the enterprise plan required for custom approval wouldn't be enabled on instances.
-
Go to CI/CD > Custom Approval. Choose
Project Owner -> DBA
as High Risk for DDL. -
Click the related risk rules beside or CI/CD > Risk Center. Add on top right. Set
High
Risk andDDL
asThe risk for the production environment is considered to be high.
-
Click Settings (the gear icon) and add a DBA account. Click it in the Active members list, and edit its password. You'll need this account later to do the approval.
-
Within Workspace, go to Environments > Prod. Now the third option for rollout policy
Manual rollout by the last approver from the custom approval
is unlocked. Choose it. -
Go to
Sample Project
, choose both databases to Edit Schema. Paste this command into SQL block and Create.
- The approval flow is matched. Since it's in the pipeline, it will be brought forward to the
Test
stage to review earlier. Follow its order to approve. ADBA
will be the one to do the rollout. If you didn't have a DBA in your Worksapce, you can Logout and register another DBA account, Login as the DBA to experience the entire workflow.
Summary
You have now learned how to use Bytebase to deploy schema migration in a basic way. Bytebase also provides other advanced features for your interests:
- GitOps - Observe Git code push events and trigger schema migration;
- Batch changes - Change multiple databases in a single workflow;
- Changelist - Organize and apply changes sequentially, or export them for offline execution.
Join our Discord channel to discuss.