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 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

  1. 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.
  2. Copy and paste the commands to start one Bytebase via Docker.
    docker run --rm --init \
      --name bytebase \
      --publish 8080:8080 --pull always \
      --volume ~/.bytebase/data:/var/opt/bytebase \
      bytebase/bytebase:latest
    

Configure SQL Review Policies

  1. Navigate to CI/CD > SQL Review in the left menu. Click + New SQL Review to create a new SQL review.
  2. Choose Sample Template which has 20 enabled rules and click Confirm and add. Attach the SQL review to Environment Prod and click Confirm.
  3. You’ll see the SQL review is created. Note that there’s a warning sign for the NOT NULL rule. sql-review-configured sql-review-not-null

Trigger SQL Review

  1. Go to Sample Project, navigate to CI/CD > Plans and click + New Plan. new-plan
  2. Select Schema Migration (DDL) as the change type. plan-change-type
  3. 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.
  4. The plan will be in Draft status. SQL Review will run automatically, and you’ll see violations against our defined rules marked in orange as warning. plan-draft-warning plan-draft-warning-detail
  5. You may resolve this by editing the SQL to add NOT NULL constraints. Click Save to update the plan. The SQL Review checks will run again and should 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.