How to Synchronize Database Schemas
This article briefly describes the general scenarios of database schema synchronization and how to use this feature smoothly in Bytebase with pure UI operations.
Bytebase's database schema synchronization feature (introduced in 1.8.0） supports copying a specific schema version from one database to another. Without this feature, developers have to write SQL statements cautiously and apply them manually; Now with this feature, they can simply tell Bytebase which database schema needs to be replicated to the target database, and the whole process can be done from UI operations. This feature can solve the following scenarios:
During the product release process, for different environments, such as dev / staging / prod, you need to do schema synchronization. For example, the R&D release process from dev to staging, then to prod in the forward direction, or from prod to dev for testing purposes in the reverse direction.
For the production environment, databases with identical schemas, such as SaaS, multi-region game deployment, etc.
- Manual modification by humans due to special ad-hoc reasons - causes database schema drift, which needs to reconciliation
- The vendor maintains multiple product versions, so it also needs to reconcile the schema.
In the Bytebase Console:
- Select the project first;
- Select a specific database schema as the synchronization source;
- Select the database you want to sync to;
Bytebase will then calculate the schema differences between these two and automatically generate the suggested DDL statements. (e.g., ALTER TABLE ......)
Tutorial: Experience the feature in 5 mins
Here is how we install Bytebase and try out schema synchronization. Even if you have never tried Bytebase before, you can complete the process within 5 mins.
Make sure you installed Docker.
Copy and paste the commands to start one Bytebase and two MySQL instances via Docker.
Register and sign in Bytebase Console. Add two instances in two environments (Test/Prod), respectively. Username:
Create project sync-schema, and within the project, click Create DB to create databases as follows:
Go back to project sync-schema page, and click Alter Schema. Choose dbtest in Test, and click Next. Copy and paste the SQL below and click Create.
- Go back to project sync-schema page, and click Alter Schema. Choose dbprod in Prod, and click Next. Copy and paste the SQL below and click Create.
Feature Experience Phase
Go back to the project sync-schema page, click Schema-Sync, and fill in steps 1-3 to synchronize the schema of the dbtest database to dbprod:
Click Preview Issue, you will go to the new issue page with preview:
Click Create, and the Issue is truly created. Approve and Fix the issue, the schema synchronization will be completed.
In Bytebase Free, you can choose the latest history version; In Pro Plan or Enterprise Plan, you can choose an arbitrary schema version from the full migration history.
From Bytebase 1.8.0, you can start a 14-day Pro Plan or Enterprise Plan trial without credit card.
Is the experience smooth? Or do you encounter any problems? Feel free to join our Discord Group to talk about it!
In the following article, we’ll explain how Bytebase implements schema synchronization for MySQL from a technical perspective. Stay tuned!