Skip to content

Commit b0145c1

Browse files
committed
chore: sql review api
1 parent fcf924d commit b0145c1

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

content/docs/api/sql-review.md

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ title: SQL Review API
55
<TutorialBlock url="/docs/tutorials/sql-review" title="Master SQL Review with GUI, GitOps and API" />
66
<TutorialBlock url="/docs/tutorials/api-sql-review/" title="Codify SQL Review Policies with Bytebase API" />
77

8-
| | |
9-
| -------- | -------------------------------------------------------------------------------- |
10-
| Endpoint | [POST /v1/sql/check](https://api.bytebase.com/#tag/sqlservice/POST/v1/sql/check) |
11-
| Request | https://api.bytebase.com/#model/checkrequest |
12-
| Response | https://api.bytebase.com/#model/checkresponse |
13-
148
The SQL Review API provides SQL checks based on your schema review policy.
159

1610
<HintBlock type="info">
@@ -19,36 +13,28 @@ Before you start, you should configure the [SQL Review Policy](/docs/sql-review/
1913

2014
</HintBlock>
2115

22-
```text
23-
curl -X POST %%bb_api_endpoint%%/v1/sql/check \
24-
-H 'Authorization: Bearer '${bytebase_token} \
25-
-d '{
26-
"statement": "ALTER TABLE \"user\" ADD \"address\" integer; ALTER TABLE \"user\" DROP COLUMN \"age\";",
27-
"name": "instances/prod-instance/databases/example"
28-
}'
29-
```
30-
31-
```json
32-
{
33-
"advices": [
34-
{
35-
"status": "ERROR",
36-
"code": 105,
37-
"title": "schema.backward-compatibility",
38-
"content": "\"ALTER TABLE \"user\" DROP COLUMN \"age\";\" may cause incompatibility with the existing data and code",
39-
"line": 1,
40-
"column": 0,
41-
"detail": ""
42-
},
43-
{
44-
"status": "WARNING",
45-
"code": 402,
46-
"title": "column.no-null",
47-
"content": "Column \"address\" in \"public\".\"user\" cannot have NULL value",
48-
"line": 1,
49-
"column": 0,
50-
"detail": ""
51-
}
52-
]
53-
}
54-
```
16+
## Batch API (recommended)
17+
18+
| | |
19+
| -------- | ---------------------------------------------------------------------------------------------------------------------------- |
20+
| Endpoint | [POST /v1/projects/-/releases:check](https://api.bytebase.com/#tag/releaseservice/POST/v1/projects/{project}/releases:check) |
21+
| Request | https://api.bytebase.com/#model/checkreleaserequest |
22+
| Response | https://api.bytebase.com/#model/checkreleaseresponse |
23+
| Example | https://github.com/bytebase/api-example/tree/main/sql-review#batch-api-recommended |
24+
25+
Batch API allows you to validate multiple statements across multiple databases in a single API call.
26+
27+
You should use batch API for the GitOps workflow. Because a single PR or MR may contain multiple dependent
28+
migration files (e.g., `1_create_t1_table.sql`, `2_create_t1_index.sql`). By retaining the context from
29+
earlier files, the Batch API ensures each subsequent file is validated accurately.
30+
31+
## Simple API
32+
33+
| | |
34+
| -------- | -------------------------------------------------------------------------------- |
35+
| Endpoint | [POST /v1/sql/check](https://api.bytebase.com/#tag/sqlservice/POST/v1/sql/check) |
36+
| Request | https://api.bytebase.com/#model/checkrequest |
37+
| Response | https://api.bytebase.com/#model/checkresponse |
38+
| Example | https://github.com/bytebase/api-example/tree/main/sql-review#simple-api |
39+
40+
Simple API allows you to validate a single statement against a single database.

0 commit comments

Comments
 (0)