Bytebase is a database DevSecOps platform designed for developers, security, DBA, and platform engineering teams. While it offers an intuitive GUI for managing database schema changes and access control, some teams may want to integrate Bytebase into their existing DevOps platforms using the Bytebase API. This tutorial will guide you through configuring SQL review rules using the Bytebase API. This approach allows you to manage SQL review rules as code within your repository, enabling DBAs or platform engineering teams to apply them to Bytebase as needed. The tutorial repository is at https://github.com/bytebase/example-api/tree/main/sql-review. This is one of the tutorial series of SQL Review:Documentation Index
Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
Use this file to discover all available pages before exploring further.
- SQL Review with Bytebase GUI
- SQL Review with CI (integrated with Database GitOps workflow):
- SQL Review with Bytebase API
- Codify SQL Review Policies with Bytebase API (this one)
Prerequisites
- Docker installed
- Node.js >= v18
Start Bytebase
Make sure your Docker daemon is running. Copy and paste the commands to start Bytebase.localhost:8080. Register the first admin account which will be granted Workspace Admin.
Create Service Account
-
Log in as
Workspace Admin, and go to IAM & Admin > Users & Groups. Click + Add User, fill in withapi-sample, choose theWorkspace DBArole sufficient for this tutorial and click Confirm.
-
Find the newly created service account and Copy Service Key. We will use this token to authenticate the API calls.

Obtain the Access Token
- Go to Bytebase API Example repo and clone it.
-
Navigate to the
sql-reviewsubfolder and follow the instructions in theREADME.mdfile of the example code repository to execute the scripts. -
Replace
bytebase_url,bytebase_account, andbytebase_passwordin the commands below with your own values, then run them to obtain abytebase_tokenin your terminal.
Configure SQL Review Policies
-
Continue following the
README.mdto run the scripts. -
In the Bytebase console, navigate to CI/CD > SQL Review to see the applied SQL review rules. You may click Edit to change the rules.

Attach SQL Review Policies to Resources
We’ll apply these SQL review rules toenvironments or projects. Project-level rules take precedence over environment-level rules.
-
Run these command in ‘README.md’ of the repo to apply the SQL review rules to environments.
-
Continue with the
README.mdto apply the SQL review rules to projects. -
On the CI/CD > SQL Review page, you will see the SQL review rules are applied to environments and projects.

-
Go to Environments page, click Test environment to see the applied SQL review rules.

-
Go to
Sample Projectpage, click Setting on the left sidebar to see the applied the SQL review rules.
-
To detach SQL review policies from environments, use the following commands:
Similarly as to detach from projects:
-
To delete the SQL review rules, use the following commands:

