Deploy Schema Change 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.6.0
-
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)
If you want the approval flow to be more dynamic based on the context like the type of SQL statements, follow this tutorial Database Change with Risk-Based Approval Flow.
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.