Batch Change with Database Group
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.
Preparation
-
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
. -
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.
-
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
-
Regsiter an admin account and it will be granted the
workspace admin
role automatically. -
Go to Environments, update the existing
Prod
environment toProdAsia
and then create two new environmentsProdEU
andProdNA
.
Step 2 - Create databases
-
Bytebase provides two sample PostgreSQL instances. Click
Select Project
on the top bar, and click New Project on the popup. Fill it with a namebatch project
and create Create. -
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, createdemo-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. -
In the same way, create
demo-prod-1
anddemo-prod-2
which should be created onProdAsia
environment.demo-prod-3
anddemo-prod-4
should be created onProdEU
environment.demo-prod-5
anddemo-prod-6
should be created onProdNA
environment.
Step 3 - Batch change by environment (Community Plan)
-
Go to Databases > Database in the project, select
demo-test
anddemo-prod-1
~demo-prod-6
and click Edit Schema. -
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);
-
After all the databases are rolled out, you can see the issue is done.
Step 4 - Database group (Pro/Enterprise Plan)
We need first to upgrade to Pro/Enterprise Plan to use Database Group.
-
Click the Setting icon on the top right, and then click Workspace > Subscription to upload the license.
-
Click the pen icon, select the instances you want to enable Enterprise features , and click Confirm.
-
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
- Name:
-
Go to Database > Groups in the project, click Change > Edit Schema.
-
You many see the six databases in three stages. Fill in the SQLs and click Create.
CREATE TABLE t3("id" INTEGER NOT NULL);
Summary
Now you have learned how to configure environment and database group to run batch changes in Bytebase.