Database CI/CD Best Practice with Azure DevOps
Hi and welcome to Database DevOps Academy #18!
Each week, we share Database DevOps insights and best practices for modern engineering organizations. If you enjoy this newsletter, we ask you to subscribe and share. ??
In this Issue, we explore Database CI/CD Best Practice for Azure. Enjoy!
Wanna try other VCS providers instead? ??
Database change is a tricky part of the application development process: it usually involves multiple databases from different environments and cross-team collaboration, to add on top of it, databases are touch and go. It got us thinking: can we treat database the same way we treat application code?
DORA (DevOps Research & Assessment) pointed out that integrating database work into the software delivery process positively contributes to continuous delivery. It’s about time to make databases a part of the CI/CD cycle.
But how does it work, really?
A Complete Database CI/CD Workflow
Here, we present a complete Database CI/CD workflow with Azure DevOps. It's similar with GitHub, Bitbucket or Azure DevOps.
Set Up Database CI/CD with Azure DevOps in Bytebase (Free Plan)
Here's a step-by-step tutorial on how to set up this Database CI/CD with Azure DevOps in Bytebase.
Step 1 - Run Bytebase in Docker and set the External URL generated by ngrok
ngrok is a reverse proxy tunnel, and in our case, we need it for a public network address in order to receive webhooks from VCS. ngrok we used here is for demonstration purposes. For production use, we recommend using Caddy .
ngrok http 5678
docker run --init \
--name bytebase \
--restart always \
--publish 5678:8080 \
--health-cmd "curl --fail https://localhost:5678/healthz || exit 1" \
--health-interval 5m \
--health-timeout 60s \
--volume ~/.bytebase/data:/var/opt/bytebase \
bytebase/bytebase:2.9.1 \
--data /var/opt/bytebase \
--port 8080
Step 2 - Add Azure DevOps as a Git provider in Bytebase
On the Azure DevOps application registration page, fill the form as follows:
Click Register application.
Click show. Copy the App ID and Client Secret and paste them into the Bytebase GitOps config page. Click Next. Click Authorize on popup. You will be redirected to the confirmation page. Click Confirm and add, and the Git provider is successfully added.
Step 3 - Configure a GitOps Workflow in Bytebase
Step 4 - Create a Pull Request and Trigger SQL Review CI
领英推荐
ALTER TABLE "public"."employee"
ADD COLUMN "nick_name" text;
ALTER TABLE "public"."employee"
ADD COLUMN "nick_name" text NOT NULL DEFAULT '';
Advanced Features (Enterprise Plan)
You may upgrade to Enterprise plan to explore more features.
Click Start free trial on the left bottom and upgrade to Enterprise plan, Go to Instances to Assign License for the existing two instances.
Manual Rollout
Go to Environments > 2.Prod, Find Rollout policy section, and choose Manual rollout by fixed roles with all items checked.
Custom Approval
LATEST Schema Write-back
After schema migration completes, Bytebase will write the latest schema back to the Git repository. So that the team always has a canonical source of truth for the database schema in Git.
ALTER TABLE "public"."employee"
ADD COLUMN "country" text NOT NULL DEFAULT '';
Schema Drift
Bytebase has built-in schema drift detection to detect unexpected schema changes. Let's use the SQL Editor Admin Mode to simulate this.
ALTER TABLE "public"."employee"
ADD COLUMN "city" text NOT NULL DEFAULT '';
Summary
Now with Bytebase, you have a complete Database CI/CD workflow with Azure DevOps. You can apply this workflow to your own project and customize it to fit your needs. If you have any questions, please feel free join and discuss in Discord .