DevOps: Database Change Management with PostgreSQL and GitHub

Estimated: 30 mins
DevOps: Database Change Management with PostgreSQL and GitHub

A series of articles about DevOps: Database Change Management with PostgreSQL


In the last article DevOps: Database Change Management with PostgreSQL, you have tried UI workflow in Bytebase.

This tutorial will bring you 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 free version to finish the tutorial.


Before you start this tutorial, make sure:

Step 1 - Run Bytebase in Docker and set the External URL generated by ngrok

ngrok is a reverse proxy tunnel, and in our case, we need it for a public network address in order to receive webhooks from VCS. ngrok we used here is for demonstration purposes. For production use, we recommend using Caddy.


  1. Login to ngrok Dashboard and follow its Getting Started steps to install and configure.

  2. Run ngrok:

    ngrok http 5678

    and obtain the public URL terminal-ngrok

  3. Run Bytebase in Docker with the following command:

    docker run --init \
      --name bytebase \
      --restart always \
      --publish 5678:8080 \
      --health-cmd "curl --fail http://localhost:8080/healthz || exit 1" \
      --health-interval 5m \
      --health-timeout 10s \
      --volume ~/.bytebase/data:/var/opt/bytebase \
      bytebase/bytebase:2.11.1 \
      --data /var/opt/bytebase \
      --port 8080
  4. Bytebase is running successfully in Docker, and you can visit it via localhost:5678. Register an admin account and it will be granted the workspace admin role automatically.

  5. Click the gear icon (Settings) on the top right. Click General under Workspace. Paste as External URL under Network section and click Update.


  6. Bytebase is running successfully in Docker, and you can visit it via

Step 2 - Find your PostgreSQL instance in Bytebase

  1. Visit Bytebase Console through the browser via your ngrok URL. Log in using your account created from the previous tutorial. bb-login

  2. If you have followed the last article, you should have a Project Sample Project and a database demo. bb-home

Step 3 - Connect Bytebase with

  1. Click Settings on the top bar, and then click Workspace > Version Control. Choose and click Next. bb-settings-vc-step1

  2. Follow the instructions within STEP 2, and in this tutorial, we will use a personal account instead of an organization account. The configuration is similar. bb-settings-vc-step2

  3. Go to your GitHub account. Click Settings on the dropdown menu. gh-settings-dropdown

  4. Click Developer Settings at the bottom of the left side bar. Click OAuth Apps, and click New OAuth App. gh-oauth-apps

  5. Fill Application name and then copy the Homepage and Authorization callback URL in Bytebase and fill them. Click Register application. gh-register-oauth

  6. After the OAuth application is created successfully. Click Generate a new client secret. Copy Client ID and this newly generated client secret and paste them back in Bytebase. gh-copy-client-id bb-vc-client-id

  7. Click Next. You will be redirected to the confirmation page. Click Confirm and add, and the Git provider is successfully added. gh-auth bb-settings-vc-step3

Step 4 - Enable GitOps workflow with PostgreSQL

  1. Go to project Sample Project, click Version Control, and choose GitOps Workflow. Click Configure GitOps. bb-project-vc-gitops

  2. Choose - the provider you just added. It will display all the repositories you can manipulate. Choose pg-test-bb-local. bb-project-vc-github bb-project-vc-github-local

  3. Keep the default setting, and click Finish. bb-project-vc-gitops-enabled

Step 5 - Change schema for PostgreSQL by pushing SQL schema change files to GitHub

  1. In your GitHub repository pg-test-bb-local, create a folder bytebase, then create a subfolder Prod, and create an sql file following the pattern {{ENV_ID}}/{{DB_NAME}}##{{VERSION}}##{{TYPE}}##{{DESCRIPTION}}.sql. It is the default configuration for file path template setting under project version control.


    • prod corresponds to {{ENV_ID}}
    • demo corresponds to {{DB_NAME}}
    • 202316410000 corresponds to {{VERSION}}
    • ddl corresponds to {{TYPE}}
    • create_t2 corresponds to {{DESCRIPTION}}

    Paste the sql script in it.

   "public"."t2" (
   "id" integer NOT NULL,
   "name" character varying(255) NOT NULL,
   PRIMARY KEY ("id")

   ON COLUMN "public"."t2"."id" IS 'ID';


  1. Commit and push this file.

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

  3. Click issue/105 and go the issue page, you’ll see

    • The issue is created via
    • The issue is waiting for your approval because it’s on Prod environment where manual approval is required by default.
    • The SQL is exactly the one we have committed to the GitHub repository.
    • The Creator is A, because the GitHub user you use to commit the change has the same email address found in the Bytebase member list. bb-issue-demo
  4. Click Approve, and the SQL will execute. Click Resolve issue, and the issue will be Done. bb-issue-done

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

  6. Go to GitHub repository, you will see besides your committed sql, there is a .demo##LATEST.sql file. Because you have configured Schema path template before, Bytebase will write back the latest schema to that specified path after completing the schema change. Thus you have access to an update-to-date full schema at any time. gh-LATEST

Summary and Next

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

In real world scenario, you might have separate features and main branches corresponding to your dev and production environment, you can check out GitOps with Feature Branch Workflow to learn the setup. Have a try and look forward to your feedback!

Edit this page on GitHub

Subscribe to Newsletter

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