Database CI/CD and Schema Migration with GitHub using Bytebase Cloud

Estimated: 30 mins
Database CI/CD and Schema Migration with GitHub using Bytebase Cloud

A series of articles about Database Change Management using Bytebase Cloud. We take Amazon Aurora MySQL as an example and is also applicable to Amazon Aurora Serverless.


In the last article Database Change Management using Bytebase Cloud, you have tried UI workflow in Bytebase.

This tutorial will bring your schema change to the next level by introducing the GitOps workflow, where you commit the schema change script to the GitHub repository, which will in turn trigger the schema deployment pipeline in Bytebase.

You can use Bytebase's Community Plan to finish the tutorial.

Features included

  • GitOps Workflow

Prerequisites

Before you start this tutorial, make sure you have the following ready:

Step 1 - Connect Bytebase with GitHub.com

  1. Go to Bytebase homepage, and click Integration > GitOps on the left sidebar. Choose GitHub.com as Git provider. What we need is a github personal access token. bb-gitops-no-access-token

  2. Go to your GitHub account. Click your avatar and then click Settings on the menu. Click Developer settings on the left sidebar, and then click Personal access tokens > Fine-grained tokens. gh-fine-grained-tokens

  3. Click Generate new token, fill in the fields and check the scopes according to the description on Bytebase. Click Generate token.

  4. Copy the token and paste it back into Bytebase Integration > GitOps. Click Confirm and add. bb-gitops-access-token

Step 2 - Enable GitOps workflow

  1. Go to the project Sample Project, click Integration > GitOps. Click Add Enable GitOps connector. bb-project-gitops-add

  2. Choose GitHub.com - the provider you just added. It will display all the repositories you can manipulate. Choose test-bb-gitops. bb-project-select-repo

  3. Keep the default setting, and click Finish. Pay attention to Database Group, which is the database group that the schema change will be applied to. With Community Plan, the changes will automatically affect all databases in the project. With Enterprise Plan, you'll have the option to specify the target database group. bb-project-gitops-configure

Step 3 - Change schema by pushing SQL schema change files to GitHub

  1. In your GitHub repository test-bb-gitops, create a folder bytebase, then create an sql file 202404151600_create_table_t1.sql.

    Paste the sql script in it.

    CREATE TABLE t1 (
       "id" INTEGER NOT NULL
    );
  2. Create a new branch for this commit and start a pull request. Click Merge pull request to merge the new branch into the main branch. gh-create-table

  3. Go to Bytebase, and go into project Sample Project. You’ll find there is a new Push Event and a new issue created. bb-push-notification-only

  4. Click and go to the issue page, you’ll see

    1. The issue is created via GitHub.com, there's a link to the GitHub commit.

    2. The SQL is exactly the one we have committed to the GitHub repository.

    3. The SQL has passed the automatic task checks and rollout automatically.

    4. Since there're two databases in the project, Bytebase creates a 2-staged pipeline to roll out the change sequentially.

      bb-issue-done

  5. Click View change, you can view the schema diff. bb-schema-diff

Summary and What's Next

Now you have tried out GitOps workflow, which will store your database schema in GitHub and trigger the change upon committing the change to the repository via Pull Request, to bring your database change workflow to the next level of Database DevOps - Database as Code.

If the built-in workflow is not suitable, you can opt to Bytebase API to fully customize the workflow to integrate with your CI pipeline. Automating Database Schema Change workflow Using GitHub Actions is an example.

Edit this page on GitHub

Subscribe to Newsletter

By subscribing, you agree with Bytebase's Terms of Service and Privacy Policy.