Lesson 5 of 6 · Database CI/CD

Building the Pipeline

A database CI/CD pipeline in GitHub Actions with Liquibase: CI on pull requests, CD through each environment with approvals, recovery, and metrics.

Beginner 7 sections 4 min read

Designing a database pipeline

A database CI/CD pipeline has two halves. The CI half runs on every pull request and proves the change is good. The CD half runs after the merge and carries the same change through each environment in turn, with an approval before production. This lesson builds both with GitHub Actions and Liquibase; the same design works in GitLab CI, Jenkins, or Azure Pipelines.

CI · EVERY PULL REQUEST Lint andpolicy checksApply to anOracle containerUnit tests(utPLSQL)Rollback test,results on the PR CD · AFTER MERGE TO MAIN Deploy to testautomaticallyDeploy to stagingproduction-sizedApproval, withthe SQL preview Deploy to production,tag the release Monitoring watches every environment after each deployment.

The repository

sales-db/
├── db/
│   ├── changelog.xml              # lists the changelog files, in order
│   ├── changes/
│   │   ├── 2026-10-DBA-301-orders.sql
│   │   └── 2026-11-DBA-310-vbuck-points.sql
│   └── tests/test_vbuck_points.pkb     # utPLSQL tests
├── .github/workflows/
│   ├── db-ci.yml                  # runs on pull requests
│   └── db-cd.yml                  # runs after merge to main
└── CODEOWNERS                     # db/ needs a DBA's approval

The CI workflow

# .github/workflows/db-ci.yml
name: Database CI
on:
  pull_request:
    paths: ["db/**"]

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      oracle:                                   # a throwaway Oracle database for this run
        image: gvenzl/oracle-free:23-slim
        env:
          ORACLE_PASSWORD: ${{ secrets.CI_ORACLE_PASSWORD }}
          APP_USER: sales
          APP_USER_PASSWORD: ${{ secrets.CI_SALES_PASSWORD }}
        ports: ["1521:1521"]
        options: --health-cmd healthcheck.sh --health-interval 10s --health-retries 30
    env:
      LIQUIBASE_COMMAND_URL: jdbc:oracle:thin:@localhost:1521/FREEPDB1
      LIQUIBASE_COMMAND_USERNAME: sales
      LIQUIBASE_COMMAND_PASSWORD: ${{ secrets.CI_SALES_PASSWORD }}
      LIQUIBASE_COMMAND_CHANGELOG_FILE: db/changelog.xml
    steps:
      - uses: actions/checkout@v4
      - name: Lint SQL
        run: pipx run sqlfluff lint db/changes --dialect oracle
      - name: Install Liquibase and utPLSQL-cli
        run: ./ci/install-tools.sh               # downloads pinned versions
      - name: Apply, roll back, and re-apply every change
        run: liquibase update-testing-rollback
      - name: Run unit tests
        run: utplsql run "sales/${{ secrets.CI_SALES_PASSWORD }}@//localhost:1521/FREEPDB1" -f=UT_JUNIT_REPORTER -o=test-results.xml

Branch protection on main requires this workflow to pass, and CODEOWNERS requires a DBA's approval for anything in db/, before a pull request can be merged.

The CD workflow

# .github/workflows/db-cd.yml (simplified)
name: Database CD
on:
  push:
    branches: [main]
    paths: ["db/**"]

jobs:
  test:
    runs-on: ubuntu-latest
    environment: test                      # test's credentials, stored in GitHub
    steps:
      - uses: actions/checkout@v4
      - run: ./ci/install-tools.sh
      - run: liquibase update

  staging:
    needs: test
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - ...same steps, against the production-sized staging copy...

  production:
    needs: staging
    runs-on: ubuntu-latest
    environment: production                # protected: the DBA team must approve
    steps:
      - uses: actions/checkout@v4
      - run: ./ci/install-tools.sh
      - name: Save the exact SQL that will run, for the record
        run: liquibase update-sql > release-preview.sql
      - name: Mark the current state, to roll back to if needed
        run: liquibase tag "before-${{ github.sha }}"
      - name: Deploy
        run: liquibase update
Environments and approvals
Each GitHub environment holds its own secrets, such as connection details, and the production environment requires approval from named reviewers, such as the DBA team. The run pauses there until someone approves, and records who did.
The same change, everywhere
Every environment gets exactly the same changelog, from the same commit, applied the same way. Production never sees a change that hasn't passed test and staging.
The preview
update-sql saves the exact SQL that will run in production, so the approver can read it and the audit trail keeps it.

When a release goes wrong

Roll forward
Usually the fastest fix: write a new migration that corrects the problem, and send it through the pipeline. Most teams prefer this for anything that touched data.
Roll back
For simple, structural changes, such as a new index or view, run the changeset's rollback, for example liquibase rollback before-<commit>. Don't roll back changes that would lose data.
Restore
The last resort, for serious damage: point-in-time recovery or flashback to before the release. It's why a recent backup is a precheck for production releases.

Measuring the pipeline

The DORA metrics from Introduction to DevOps apply directly to database changes:

MetricFor database changes
Deployment frequencyHow often schema changes reach production
Lead time for changesFrom a changeset's commit to running in production
Change failure rateThe share of database releases that cause an incident or need fixing
Time to restoreHow long it takes to recover from a bad database release

Key takeaways

  • CI runs on every pull request: lint, apply to a throwaway database, unit tests, and a rollback test.
  • CD runs after merge: the same change goes to test, staging, and, after approval, production.
  • GitHub environments hold each environment's secrets and enforce approvals before production.
  • Save the exact SQL preview and tag the database before every production release.
  • Fix bad releases by rolling forward, rolling back simple changes, or, as a last resort, restoring.
  • Track deployment frequency, lead time, change failure rate, and time to restore.