Skip to content




bytebase

https://www.bytebase.com/

Bytebase is an open-source database DevOps tool, it's the GitLab/GitHub for managing databases throughout the application development lifecycle. It offers a web-based collaboration workspace for DBAs, Developers and platform engineers.

gitops

https://www.bytebase.com/docs/vcs-integration/overview/

GitOps with VCS Integration

"Version controlled schema" aka "Database-as-code" is a practice to store the database schema in a version control system (VCS) just like how application code is stored. The database schema consists of a bunch of database migration scripts. In this model, the migration scripts are the source of truth of the database schema.

adding database instances to bytebase

I have bytebase running on my kubernetes cluster. I create database instances on kubernetes cluster using operators such as postgres-operator and mongodb-operator. And for the database instances I want to manage using bytebase, I add them by following steps:

  • environments "prod" and "test" are there by default, and add another one as necessary
  • add existing database instance on bytebase
    • database product
    • destination name/ipaddr and port
    • credentials
  • create a new project on bytebase, to give it a label bytebase uses
  • create a database on bytebase
    • choose project created above
    • give it a name
    • select environment
    • select instance

I end up having a database on bytebase with instances on different servers and different environment.

setup git provider on bytebase

https://www.bytebase.com/docs/vcs-integration/self-host-gitlab/

I then setup an integration of gitlab and bytebase.

  • set gitlab instance URL on bytebase
  • create a new application on gitlab
    • set callback URL
    • set API as application scope
  • set the application ID and secret provided by gitlab on bytebase gitops setup wizard

I now have the VCS integration with my self-managed gitlab. Next I configure bytebase project gitops workflow.

setup gitops workflow on bytebase project

https://www.bytebase.com/docs/vcs-integration/enable-gitops-workflow/

  • select the created bytebase project and navigate to integration > gitops and start the setup
  • choose the git provider created in previous steps
  • select repository on the git provider
  • configure deployment
    • branch name
    • base directory in the repository for bytebase to watch
    • file path template

making changes through bytebase gitops

Here is the default file path template.

{{ENV_ID}}/{{DB_NAME}}##{{VERSION}}##{{TYPE}}##{{DESCRIPTION}}.sql

Assuming the repository is "myrepo/mydb", the base directory is "bytebase", the name of the database added to the bytebase project is "bbdb" in "prod" environment, you can trigger the gitops workflow by creating a file like this on the repository:

file path on myrepo/mydb repository
bytebase/prod/bbdb##v0.1##ddl##create_table.sql
bbdb##v0.1##ddl##create_table.sql
CREATE TABLE student
(
student_id INT,
student_name VARCHAR(30),
student_age INT,
student_address VARCHAR(25),
student_phone_no VARCHAR(20)
);

DDL and DML

https://www.bytebase.com/docs/vcs-integration/name-and-organize-schema-files/

DDL, schema migration type, and DML, data migration type can be executed through bytebase gitops.

Previous one with "ddl" in its name for the type is the example of DDL change to create a table.

Here are the example file names from the official document on both ddl and dml.

# ddl
bytebase/env1/db1##202101131000##ddl##create_tablefoo_for_bar.sql

# dml
bytebase/env1/db1##202101131000##dml##change_for_bar_data.sql

version

A common practice is to use timestamp like YYYYMMDDHHMMSS or v1, v2 as the version name