Skip to content

Latest commit

 

History

History

sql-review

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

SQL Review

Corresponding tutorial 🔗.

This example demonstrates how to use API to configure SQL Review policies. This example defines the following review policies:

  • basic. Applies to environment test and project basic.
  • advanced. Applies to environment prod.

Fetch the access token with service account

To call the Bytebase API, you need to use service account.

export bytebase_url=http://localhost:8080
export [email protected]
export bytebase_password=bbs_***********8Tdcm
bytebase_token=$(curl -v ${bytebase_url}/v1/auth/login \
   --data-raw '{"email":"'${bytebase_account}'","password":"'${bytebase_password}'","web":true}' \
   --compressed 2>&1 | grep token | grep -o 'access-token=[^;]*;' | grep -o '[^;]*' | sed 's/access-token=//g; s/;//g')
echo $bytebase_token

Configure SQL Review policy

Upsert

curl --request PATCH "${bytebase_url}/v1/reviewConfigs/basic?allow_missing=true&update_mask=rules" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @policy/basic.json

curl --request PATCH "${bytebase_url}/v1/reviewConfigs/advanced?allow_missing=true&update_mask=rules" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @policy/advanced.json

Delete

curl --request DELETE ${bytebase_url}/v1/reviewConfigs/basic \
  --header 'Authorization: Bearer '${bytebase_token}

curl --request DELETE ${bytebase_url}/v1/reviewConfigs/advanced \
  --header 'Authorization: Bearer '${bytebase_token}

Attach policy to environment

Attach

curl --request PATCH "${bytebase_url}/v1/environments/test/policies/tag?allow_missing=true&update_mask=payload" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @binding/environments/test.json

curl --request PATCH "${bytebase_url}/v1/environments/prod/policies/tag?allow_missing=true&update_mask=payload" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @binding/environments/prod.json

Remove

curl --request DELETE ${bytebase_url}/v1/environments/test/policies/tag \
  --header 'Authorization: Bearer '${bytebase_token}

curl --request DELETE ${bytebase_url}/v1/environments/prod/policies/tag \
  --header 'Authorization: Bearer '${bytebase_token}

Attach policy to project

Attach

curl --request PATCH "${bytebase_url}/v1/projects/project-sample/policies/tag?allow_missing=true&update_mask=payload" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @binding/projects/project-sample.json

Remove

curl --request DELETE ${bytebase_url}/v1/projects/project-sample/policies/tag \
  --header 'Authorization: Bearer '${bytebase_token}

Check Statements

Batch API (recommended)

curl --request POST "${bytebase_url}/v1/projects/project-sample/releases:check" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @check/batch.json

Simple API

curl --request POST "${bytebase_url}/v1/sql/check" \
  --header 'Authorization: Bearer '${bytebase_token} \
  --data @check/simple.json