How to Setup Database CI/CD with GitHub, Part 1: Enable SQL Review with GitHub Actions
A series of articles about Database CI/CD with GitHub
-
How to Setup Database CI/CD with GitHub Part 1-3
- Part 1: Enable SQL Review with GitHub Actions (this one)
- Part 2: GitHub.com Database GitOps
- Part 3: Put Them Together
In the last article The Database CI/CD Best Practice with GitHub, we raised a question: "can we treat database the same way we treat application code?" and presented a complete database CI/CD workflow with GitHub.
To bring the idea into reality, we broke it down into a three-part tutorial series How to Setup Database CI/CD with GitHub:
- Enable SQL Review with GitHub Actions (this one)
- GitHub.com Database GitOps
- Put Them Together
You can choose to implement GitHub actions, GitOps, or both by following all three.
This first article will guide you to enable SQL Review GitHub actions (developed by Bytebase) when there is a pull request in your repository.
Bytebase deployment is not needed for this tutorial.
Here is a completed example repository: https://github.com/Bytebase/sql-review-action-example.
Step 1 - Create a Repository on GitHub with two folders
.github/workflows/
to put the configuration filesgithub-action-test/
to put the test SQLs, actually you can name the folder whatever you want.
Step 2 - Download the SQL review guide template
- Go to bytebase.com/sql-review-guide, and choose Dev.
- Filter with MySQL, now you have all the available SQL review rules. Click Download as YAML and you will get a YAML file called
sql-review.yml
. Rename it tobb.sql-review.dev.yml
.
- Move the
bb.sql-review.dev.yml
file under your repo's root directory. Theoretically, you can put it anywhere within the project (just to make sure it's outside of .github/).
Step 3 - Configure sql-review.yml
- Go to SQL Review GitHub Action on GitHub marketplace, and follow the Usage section: Create a file
sql-review.yml
under the.github/workflows
folder, and paste the content template.
- Configure the file to fit your need.
Step 4 - Open a PR (Pull Request) to trigger the SQL Review Github Actions
- Create a new branch.
- Add a
.sql
file under thegithub-action-test
folder.
- Commit and push, then create a PR on GitHub. The SQL review will run automatically.
- Click on Actions tab, and you will see there are two warnings regarding this particular SQL.
- Because they’re warning level, you can still merge the PR.
- However, if you want this “fail” to block the merge, you can do either of the following:
- Adjust the rule to
Error
level on bytebase.com/sql-review-guide before downloading the template file.
- Or edit the level field on the review rule list directly in your YAML file.
Congratulations! Now you have enabled SQL Review GitHub Actions for your GitHub repo. In the next part of this series, we’ll explore part 2: GitHub.com Database GitOps.
Ready to try out this Database CI/CD workflow yourself? Join our Discord channel and share your experience.