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 all plans)
- Level 3 - Custom Approval (available in Enterprise)
Preparation
-
Make sure your Docker is running, and start the Bytebase Docker container with the following command:
docker run --rm --init \ --name bytebase \ --publish 8080:8080 --pull always \ --volume ~/.bytebase/data:/var/opt/bytebase \ bytebase/bytebase:3.5.1
-
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
- Check
automatic
asRollout policy
. 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 (with 20 rules).
- Check
-
Click SQL Review 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:ALTER TABLE "public"."employee" ADD COLUMN "country" text;
-
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:
ALTER TABLE "public"."employee" ADD COLUMN "country" text NOT NULL DEFAULT '';
-
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(Community Plan)
You can specify multiple pre-defined roles to manually roll out the change.
If you want Time scheduling feature, you will need to upgrade to Pro Plan.
-
Within Workspace, go to Environments > Prod. Uncheck
Automatic
. Choose several roles according to your needs and also checkIssue Creator
. 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.ALTER TABLE "public"."employee" ADD COLUMN "city" text NOT NULL DEFAULT '';
-
Task checks runs. SQL runs on
Test
automatically but waits to run onProd
. Click Rollout to trigger directly.
Level 3: Manual rollout with custom approval (Enterprise Plan)
You can request a Enterprise trial.
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 IAM&Admin > Users&Groups 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. Choose
Last Issue Approver
asRollout policy
. -
Go to
Sample Project
, choose both databases to Edit Schema. Paste this command into SQL block and Create.
ALTER TABLE "public"."employee"
ADD COLUMN "district" text NOT NULL DEFAULT '';
- 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.