Batch Change with Database Group
Bytebase offers multiple features to simplify batch change management. In this tutorial, we will guide you on how to use Deployment Configure and Database Group to batch change databases for various scenarios.
- The graph above is for Step 2 - Deployment Configure (Community Plan)
- The graph above is for Step 3 - Database Group (Enterprise Plan) & Step 4 - Multitenancy Database Group (Enterprise Plan)
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
. -
Deployment configure is a Community Plan feature and Database group is an Enterprise 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 databases
To demonstrate the batch change, we need to prepare some databases first.
-
Copy and paste the commands to start one Bytebase via Docker.
-
Regsiter an admin account and it will be granted the
workspace admin
role automatically. -
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, since we haven't configured any rollout mechanism or custom approval workflow, it will roll out automatically. After the issue is done, the database is created. -
In the same way, create
demo-prod-1
,demo-prod-2
,demo-prod-3
,demo-prod-4
,demo-prod-5
,demo-prod-6
,other-prod-1
andother-prod-2
. -
Select both
demo-prod-1
anddemo-prod-2
, and click Edit Labels. Assign a label Key:Location
, Value:Asia
. -
In the same way, assign
EU
andNA
to other demo-prod databases.
Step 2 - Deployment Configure (Community Plan)
We'll show you the difference deployment configuration makes.
-
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 two stages - Test and Prod, and there're six databases, which means the SQL will run against these six databases simutaneously. -
What if we want to do the change to Asia first, then EU,and NA the last? Stay in the project, click Deployment Configure on the leftside bar. Add new stages with label filtering.
-
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 as we configure.
Step 3 - Database Group (Enterprise Plan)
We need first to upgrade to 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:
Environment == Prod
&Database name startsWith demo-prod-
- Name:
-
Go to Database > Groups in the project, click Edit Schema, and choose Database group and click Next.
-
You many see the six databases in three stages. Fill in the SQLs and click Create.
-
Go to Database > Databases in the project, and click New DB. Create a database
demo-prod-7
which belongs to the database group. Check the schema, it's empty.
Step 4 - Multitenancy Database Group (Enterprise Plan)
When the database group has Multitenancy enabled, the new database will inherit group schemas automatically.
-
Go to Database > Groups in the project, click Configure, this time we check Multitenancy and click Confirm.
-
Go to Database > Databases in the project, and click New DB. Create a database
demo-prod-8
which belongs to the database group. Check the schema, it's the same schema as other demo-prod databases. Pay attention here, even if there is an on going issue, the new database will be appended.
Summary
Now you have learned how to use deployment config and database group to run batch changes in Bytebase.