Deploy Schema Migration with Rollout Policy

Estimated: 30 mins

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.

graph-4-steps

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

Preparation

  1. 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:2.23.1
  2. Bytebase is running successfully in Docker, and you can visit it via localhost:8080. Register an admin account and it will be granted the workspace admin role automatically.

Level 1: Automatic rollout with SQL review (Community Plan)

  1. Within Workspace, go to Environments > Test and Environments > Prod, you'll see

    • Rollout policy is automatic. Unless there's warning or error, rollout will be automatically executed after an issue is created.
    • SQL Review is enabled on Prod with a sample policy.

    environment-settings-default

  2. 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.

  3. Go to Sample Project from top left. Go to Database > Databases, choose both hr_prod and hr_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;
  4. SQL Review will run automatically along with some other checks. You'll see a warning for the task on Prod. Click Prod Stage of the pipe above for details.

    prod-warning-detail

  5. Edit the SQL statement with this:

    ALTER TABLE "public"."employee"
    ADD COLUMN "country" text NOT NULL DEFAULT '';
  6. Now you'll see the warning disappear and the issue rolls out automatically. Click View change to see the diff.

    view-change

Level 2: Manual rollout with dedicated roles and scheduled time (Pro Plan)

To test the Pro feature, you can subscribe the Pro plan for 1 month or request a Enterprise trial.

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.
  1. Within Workspace, go to Environments > Prod. Choose Manual rollout by dedicated roles, check all but the last role. Click Update on bottom right.

    policy-manual-rollout

  2. 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 '';
  3. Task checks runs. SQL runs on Test automatically but waits to run on Prod. Click Rollout to trigger directly.

    issue-await

    Or set a Rollout time.

    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.

  1. Go to CI/CD > Custom Approval. Choose Project Owner -> DBA as High Risk for DDL.

    custom-approval

  2. Click the related risk rules beside or CI/CD > Risk Center. Add on top right. Set High Risk and DDL as The risk for the production environment is considered to be high.

    risk-center-add-rule

  3. 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.

  4. 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.

  5. 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 '';
  1. 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. A DBA 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.

custom-approval-await

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.

Edit this page on GitHub

Subscribe to Newsletter

By subscribing, you agree with Bytebase's Terms of Service and Privacy Policy.