Skip to main content
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. For the concepts behind this tutorial, see SQL Review: what it checks, how it differs from human approval, and how to interpret findings. This is one of the tutorial series of SQL Review:
  1. SQL Review with Bytebase GUI (this one)
  2. SQL Review with CI (integrated with Database GitOps workflow):Add commentMore actions
  3. SQL Review with Bytebase API
  4. Codify SQL Review Policies with Bytebase API
This tutorial will walk you through using SQL Review in Bytebase with Bytebase GUI to improve your database schema change process. The Community Plan is sufficient for completing this tutorial.

Prerequisites

Make sure you have Docker installed, and if you don’t have important existing Bytebase data locally, you can start over from scratch by rm -rf ~/.bytebase/data.

Start Bytebase with sample data

  1. Ensure Docker is running, then start the Bytebase container:
    dk-bb-running
  2. Open Bytebase in localhost:8080, fill in the fields and click Create admin account. You’ll be redirected to Workspace. account
  3. During workspace setup, choose the built-in sample data. setup-built-in-sample-data

Configure SQL Review Policies

  1. Navigate to CI/CD > SQL Review in the left menu. Click Create to create a new SQL review policy.
  2. Choose Sample Template, which has 19 enabled rules, and click Next, then Create. Attach the SQL review policy to Environment Prod and click Confirm.
  3. You’ll see the SQL review policy is created. Note that the NOT NULL rule is set to P1. sql-review-not-null

Trigger SQL Review

  1. Go to Sample Project, navigate to CI/CD > Plans and click + New Plan.
  2. Select hr_prod database as the target since the default SQL Review policy is attached to the Prod environment. Click Confirm to proceed. You can use the Schema Editor to visually design the schema, here we’ll intentionally uncheck Not Null for nickname column.
  3. SQL Review runs automatically on the plan, and Checks reports the violation of the NOT NULL rule as P1. Click P1 to see the finding. plan-draft-warning plan-draft-warning-detail
  4. You may resolve this by editing the SQL to add NOT NULL constraints. Click Save to update the plan. The SQL Review checks run again and now pass. plan-draft-pass

Summary

Now you have learned how to trigger SQL Review in Bytebase GUI, you may also refer to the SQL Review document for more details. Next, let’s learn how to trigger SQL Review from your CI API.