Skip to content

Commit 4bd65c3

Browse files
update
1 parent f18aafa commit 4bd65c3

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

docs/tutorials/state-based-schema-management-github.mdx

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,13 @@ This is part of our database deployment series with Bytebase:
2222

2323
---
2424

25-
This tutorial shows you how to build a database state-based workflow using GitHub Actions and Bytebase API for PostgreSQL databases. Unlike migration-based approaches that track incremental changes, state-based workflows declare the desired final state of your database schema and let the system determine the necessary migrations. You'll learn to:
25+
Learn to implement state-based database schema management using GitHub Actions and Bytebase. This approach declares the desired schema state and automatically generates necessary migrations, eliminating manual script writing.
2626

27-
1. Create a state-based database workflow where you can:
28-
29-
- Define your desired database schema state in declarative SQL files
30-
- Automatically generate migration scripts based on state differences
31-
- Run SQL reviews on pull requests for generated migrations
32-
- Auto-deploy changes when merging to `main`
33-
34-
1. Handle schema drift detection and remediation
35-
36-
1. Deploy state changes via ChatOps-style PR comments
27+
**What you'll build:**
28+
- Declarative schema definitions in SQL files
29+
- AI-powered SQL reviews on pull requests
30+
- Auto-deployment of state changes on merge to main
31+
- Schema drift detection and correction
3732

3833
<Info>
3934

@@ -56,7 +51,7 @@ This tutorial shows you how to build a database state-based workflow using GitHu
5651

5752
**State-based**: Declare the desired schema state. The system automatically generates migrations by comparing current and desired states.
5853

59-
## Prepare the Environment
54+
## Setup
6055

6156
### Step 1 - Set up Bytebase
6257

@@ -117,11 +112,11 @@ run: |
117112
118113
### Step 1 - Export the Schema Definition File
119114
120-
State-based workflows use declarative SQL files that describe the complete desired state of your database schema.
115+
State-based workflows use SQL files that define the complete desired schema.
121116
122-
1. Create a state definition file under `schemas/` directory, if you want to manage your existing database schema. You may go to Bytebase console, choose a database and then click **Export Schema** to get the schema definition file.
117+
1. To manage existing schemas, export them from Bytebase console: navigate to your database and click **Export Schema**.
123118
124-
1. In this tutorial, we go to `Sample Project` and then click **Database > Databases**. Choose `hr_prod` database and click **Export Schema > Single File** to get the schema definition file as follows:
119+
1. Navigate to `Sample Project` > **Database > Databases**. Select `hr_prod` and export the schema:
125120

126121
```sql
127122
COMMENT ON SCHEMA "public" IS 'standard public schema';
@@ -138,7 +133,7 @@ State-based workflows use declarative SQL files that describe the complete desir
138133
...
139134
```
140135

141-
1. Add a new table before `audit` table. Rename the file to `schema.sql` and move it to the `schemas/` directory.
136+
1. Add a new table, save as `schema.sql` in the `schemas/` directory:
142137

143138
```sql
144139
CREATE TABLE "public"."fakeTable" (
@@ -149,12 +144,12 @@ State-based workflows use declarative SQL files that describe the complete desir
149144

150145
### Step 2 - Create a Pull Request
151146

152-
1. Commit to a new branch and create a pull request. Wait for a while, `declarative-sql-review-action.yml` workflow will be triggered and you can see the review results in the PR comments and file changes tab.
147+
1. Create a pull request from your branch. The workflow triggers automatically, posting review results as PR comments.
153148

154149
![gh-summary](/content/docs/tutorials/state-based-schema-management-github/gh-summary.webp)
155150
![gh-ai-review](/content/docs/tutorials/state-based-schema-management-github/gh-ai-review.webp)
156151

157-
1. There is a warning regarding the `fakeTable` table, we can fix by updating the schema definition file.
152+
1. Fix the naming convention warning by updating the table name:
158153

159154
```sql
160155
CREATE TABLE "public"."fake_table" (
@@ -165,26 +160,26 @@ State-based workflows use declarative SQL files that describe the complete desir
165160

166161
### Step 3 - Merge the Pull Request
167162

168-
1. Commit to the branch and push the changes. After the AI SQL review is passed, we can merge the pull request.
163+
1. Push the fix. Once the review passes, merge the PR.
169164

170-
1. Go to the **Actions** tab, you can see the workflow is running and the test stage is passed because it's automatically deployed. While the prod stage is waiting for approval.
165+
1. Check the **Actions** tab - test deploys automatically, prod awaits approval.
171166

172167
![gh-test-done](/content/docs/tutorials/state-based-schema-management-github/gh-test-done.webp)
173168

174-
1. Go to Bytebase console, you can see the release is created and the schema change is applied to the `hr_test` database.
169+
1. In Bytebase console, verify the release was created and applied to `hr_test`.
175170

176171
![bb-sdl-release](/content/docs/tutorials/state-based-schema-management-github/bb-sdl-release.webp)
177172

178173
![bb-sdl-rollout-changes](/content/docs/tutorials/state-based-schema-management-github/bb-sdl-rollout-changes.webp)
179174

180175
![bb-rollout-test-done](/content/docs/tutorials/state-based-schema-management-github/bb-rollout-test-done.webp)
181176

182-
1. Go back to GitHub **Actions** tab and approve the prod stage and wait for it to be deployed
177+
1. Return to GitHub **Actions** and approve the production deployment.
183178

184-
1. Go to Bytebase console, you can see the schema change is applied to the `hr_prod` database.
179+
1. Confirm the changes are applied to `hr_prod` in Bytebase.
185180

186181
![bb-rollout-prod-done](/content/docs/tutorials/state-based-schema-management-github/bb-rollout-prod-done.webp)
187182

188183
## Summary
189184

190-
In this tutorial, we have learned how to build a database state-based workflow using GitHub Actions and Bytebase API for PostgreSQL databases. We have also learned how to use AI review to review the schema definition file.
185+
You've successfully implemented state-based schema management with GitHub Actions, enabling declarative database changes with AI-powered reviews and automated deployments.

0 commit comments

Comments
 (0)