DEV Community

Adela
Adela

Posted on

How to Setup Database CI/CD with GitHub, Part 1: Enable SQL Review with GitHub Actions

github-database-cicd-part-1-sql-review-github-actions

This is a series of articles about Database CI/CD with GitHub


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 :

  1. Enable SQL Review with GitHub Actions (this one)
  2. GitHub.com Database GitOps
  3. 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.

divided-workflow

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 files
  • github-action-test/ to put the test SQLs, actually you can name the folder whatever you want.

create-repo

Step 2 - Download the SQL review guide template

  1. Go to bytebase.com/sql-review-guide, and choose Dev.

sql-review-guide

  1. 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 to bb.sql-review.dev.yml.

sql-review-guide-filter

  1. 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/).

move-template

Step 3 - Configure sql-review.yml

  1. 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.

sql-review-actions

  1. Configure the file to fit your need.

configure-sql-review

Step 4 - Open a PR (Pull Request) to trigger the SQL Review Github Actions

  1. Create a new branch.

new-branch

  1. Add a .sql file under the github-action-test folder.

add-sql-review-sql

  1. Commit and push, then create a PR on GitHub. The SQL review will run automatically.

sql-review-run

  1. Click on Actions tab, and you will see there are two warnings regarding this particular SQL.

sql-review-detail

  1. Because theyโ€™re warning level, you can still merge the PR.

sql-review-complete

  1. However, if you want this โ€œfailโ€ to block the merge, you can do either of the following:
  2. Adjust the rule to Error level on bytebase.com/sql-review-guide before downloading the template file.

configure-guideline

  • Or edit the level field on the review rule list directly in your YAML file.

edit-yaml

Congratulations! Now you have enabled SQL Review GitHub Actions for your GitHub repo. In the next series, weโ€™ll explore part 2: GitHub.com Database GitOps. Stay tuned!

Top comments (0)