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

