SQL Review with Bytebase API

Estimated: 30 mins

When modifying data in the database, it's crucial to ensure that the changes are both safe and accurate. Bytebase offers a feature called SQL Review, which allows you to evaluate your SQL changes before they are applied to the database. SQL Review can be invoked from the Bytebase GUI, CI or API.

This is the first part of tutorial series of SQL Review:

  1. SQL Review with Bytebase GUI
  2. SQL Review with CI (TBD)
  3. SQL Review with Bytebase API (this one)
  4. Codify SQL Review Policies with Bytebase API

This tutorial will walk you through using SQL Review in Bytebase with Bytebase API to improve your database schema change process. The Community Plan is sufficient for completing this tutorial.

Prerequisites

Make sure you have completed the previous tutorial SQL Review with Bytebase GUI.

If you want to test the SQL Review API locally, you may need to configure 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.

ngrok-reverse-proxy

  1. Run Bytebase in Docker with the following command:

    docker run --rm --init \
      --name bytebase \
      --publish 8080:8080 --pull always \
      --volume ~/.bytebase/data:/var/opt/bytebase \
      bytebase/bytebase:3.4.1
  2. Bytebase is running successfully in Docker, and you can visit it via localhost:8080. Register an admin account and it will be granted the workspace admin role automatically.

  3. Login to ngrok Dashboard and complete the Getting Started steps to install and configure. If you want to use the same domain each time you launch ngrok, go to Cloud Edge > Domains, where you'll find the domain <<YOURS>>.ngrok-free.app linked to your account.

  4. Run the ngrok command ngrok http --domain=<<YOURS>>.ngrok-free.app 8080 to start ngrok with your specific domain, and you will see the output displayed below:

    terminal-ngrok

  5. Log in Bytebase and click the gear icon (Settings) on the top right. Click General under Workspace. Paste <<YOURS>>.ngrok-free.app as External URL under Network section and click Update.

    external-url

  6. Now you can access Bytebase via <<YOURS>>.ngrok-free.app.

API Examples

You may call Bytebase API in your internal portal or GitHub Actions to trigger SQL Review. Check out https://github.com/bytebase/api-example/tree/main/issue-creation

bb-api

You can also call the API to configure SQL Review policies.

Summary

Now you have learned how to trigger SQL Review in Bytebase API. You may also refer to the SQL Review document for more details. Next, let's learn how to codify SQL Review policies with API

Edit this page on GitHub