Batch Change with Database Group

Estimated: 20 mins

Bytebase offers multiple features to simplify batch change management. In this tutorial, we will guide you on how to configure Environment and Database Group to batch change databases for various scenarios.

database-group-banner

Preparation

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

  2. Environment is a Community Plan feature and Database group is an Pro Plan feature, you need to have a valid license to enable it. You can request a trial license key from here.

Procedure

Step 1 - Start Bytebase and prepare the environments

To demonstrate the batch change, we need to prepare some databases first.

  1. Copy and paste the commands to start one Bytebase via Docker.

    docker run --rm --init \
      --name bytebase \
      --publish 8080:8080 --pull always \
      --volume ~/.bytebase/data:/var/opt/bytebase \
      bytebase/bytebase:3.5.0
  2. Regsiter an admin account and it will be granted the workspace admin role automatically.

  3. Go to Environments, update the existing Prod environment to ProdAsia and then create two new environments ProdEU and ProdNA.

    bb-env-3prod

Step 2 - Create databases

  1. Bytebase provides two sample PostgreSQL instances. Click Select Project on the top bar, and click New Project on the popup. Fill it with a name batch project and create Create.

  2. Go into project batch change, click Database > Databases on the left side bar. There is no databases belonging to this project yet. Click New DB. To mimic the real-world scenario, firstly, create demo-test which should be created on sample test instance. An issue will be created automatically, click Rollout. After the issue is done, the database is created.

    bb-new-project

    bb-issue-test-done

  3. In the same way, create demo-prod-1 and demo-prod-2 which should be created on ProdAsia environment. demo-prod-3 and demo-prod-4 should be created on ProdEU environment. demo-prod-5 and demo-prod-6 should be created on ProdNA environment.

    bb-prod-db

Step 3 - Batch change by environment (Community Plan)

  1. Go to Databases > Database in the project, select demo-test and demo-prod-1~demo-prod-6 and click Edit Schema.

    bb-edit-schema

  2. Fill in a SQL and click Create. You can see the pipeline has four stages - Test, ProdAsia, ProdEU, and ProdNA. You may select the stage and choose either rollout change to the current database or the current stage.

    CREATE TABLE t2("id" INTEGER NOT NULL);

    bb-to-rollout bb-half-rollout

  3. After all the databases are rolled out, you can see the issue is done.

    bb-complete-rollout

Step 4 - Database group (Pro/Enterprise Plan)

We need first to upgrade to Pro/Enterprise Plan to use Database Group.

  1. Click the Setting icon on the top right, and then click Workspace > Subscription to upload the license.

  2. Click the pen icon, select the instances you want to enable Enterprise features , and click Confirm.

    bb-subscription

  3. Go to Database > Groups in the project, click New database group, fill the fields as follows, when you scroll down, you will see there's an option Multitennancy, keep it unchecked for now and click Save.

    • Name: demo-prod-all
    • Condition: resource.database_name startsWith demo-prod

    bb-groups

  4. Go to Database > Groups in the project, click Change > Edit Schema.

    bb-group-change

  5. You many see the six databases in three stages. Fill in the SQLs and click Create.

    CREATE TABLE t3("id" INTEGER NOT NULL);

    bb-issue-group-to-rollout

Summary

Now you have learned how to configure environment and database group to run batch changes in Bytebase.

Edit this page on GitHub