Batch Change with Database Group
Bytebase 2.2.0 introduced database group, a new feature that provides a new way to facilitate batch change, in addition to batch changing multiple environments and multiple tenants.
As data grows, databases and tables maybe partitioned into smaller chucks. Meanwhile, you still want to apply the same database change to all partitions since they share the same schema. It's painful and error-prone to make sure a database change is consistently applied to each partition.
You can use Database Group to model those database partitions and change them in a consistent way.
Prerequisites
This tutorial requires Docker to be installed.
Step 1 - Start Bytebase and MySQL
- Make sure your Docker daemon is running. Copy and paste the commands to start one Bytebase and two MySQL instances via Docker.
Step 2 - Prepare the Console
-
Register and sign in Bytebase Console via
localhost:5678
. Click Add Instance to add two instances in two environments respectively.- Host or Socket:
host.docker.internal
| Port:3307
/3308
- Environment:
Test
/Prod
- Username:
root
| Password:testpwd1
- Host or Socket:
-
Create project
Group Demo
as Name,GD
as KeyBatch Mode
as Mode and click Create. Here you need to upgrade to Enterprise Plan with 14 days trial period. -
Within the project, click Create DB to create eight databases as follows:
demo_db_test
inTest
environment and it will run automatically. Because by default, issue inTest
environment will rollout automatically;demo_db_prod_asia
inProd
environment and click Rollout;demo_db_prod_europe
inProd
environment and click Rollout;demo_db_prod_africa
inProd
environment and click Rollout;demo_db_prod_australia
inProd
environment and click Rollout;demo_db_prod_north_america
inProd
environment and click Rollout;demo_db_prod_south_america
inProd
environment and click Rollout;demo_db_prod_antarctica
inProd
environment and click Rollout.
Step 3 - Group Databases and Create Tables in Batch
-
Within the project
Group Demo
, click Database Groups tab, and click New database group. Fill in the form as follows:- Name:
demo-all
| Environment:Prod
- Condition: Where
Database name
startsWith
demo_db_prod
You may create other database group such as: - Name:
demo-human
| Environment:Prod
- Condition: Where
Database name
startsWith
demo_db_prod
and
Database name
!=
demo_db_prod_antarctica
- Name:
-
Within the project, click Alter Schema. Choose Manual Selection > Database Group >
demo-all
, and click Next. Copy and paste the SQL below and click Create. -
On the issue page, click the down arrow and choose Rollout to run one database first. If it's OK, then click Rollout current stage to run all.
-
Repeat 2 to 3 to create another issue for another table
t2
:
Step 4 - Group Tables and Alter tables in Batch
-
Within the project
Group Demo
, click Database Groups tab, and click New table group. Fill in the form as follows:- Database Group:
demo-all
| Environment:Prod
| Name:demo-all-t
- Condition: Where
Table name
startsWith
t
- Database Group:
-
Click New table group again. Fill in the form as follows:
- Database Group:
demo-all
| Environment:Prod
| Name:demo-all-t1
- Condition: Where
Table name
==
t1
- Database Group:
-
Within the project, click Alter Schema. Choose Manual Selection > Database Group >
demo-all
, and click Next. You'll see the following field. -
Here we choose
demoall_t
which includest1
andt2
. Uncomment the last line, replace it with the SQL below and click Create. -
On the issue page, click the down arrow and choose Rollout to run one database first. If it's OK, then click Rollout current stage to run all.
Summary
Now you have learned how to use database group and table group to run batch changes in Bytebase. Bytebase also provides other ways to batch change databases across multiple environments, SaaS tenants. Please refer to Batch Change for more details.