CI integration

GitHub Action

schemadrawercom/action@v1 uploads a directory of migration files to schemadrawer.com, waits for the diagram and opens a pull request with the SVG. Nothing to install: it runs on ubuntu-latest with curl, jq and the GitHub CLI that are already there.

Usage

A workflow that redraws the diagram whenever a migration changes on main, and on demand:

name: Update schema diagram

on:
  push:
    branches: [main]
    paths: ['db/migration/**']
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  draw:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: schemadrawercom/action@v1
        with:
          sql-directory: db/migration
          output-path: docs/schema-diagram.svg
          migration-type: FLYWAY
          database-type: POSTGRESQL
          database-version: '18'
          github-token: ${{ secrets.GITHUB_TOKEN }}

The permissions block matters: the action pushes a branch and opens a pull request with the token you pass, so it needs contents: write and pull-requests: write. If the generated SVG is identical to the one already in the repository, no pull request is opened.

How it works

  1. Draw. Every file under sql-directory, subdirectories included and named relative to it, is sent to POST /api/v1/drawing together with userId, migrationType, databaseType and version. The Request-Id is derived from the workflow run and attempt, so a re-run of the same attempt is not drawn twice, and userId is derived from the repository name unless you set one.
  2. Wait. GET /api/v1/drawing/{jobId} is polled every 3 seconds, for up to timeout-seconds. On ERROR the step fails and prints the migration tool's message. On SUCCESS the SVG is downloaded to output-path.
  3. Open a pull request. A branch is created, the file committed and pushed, and a pull request opened against base-branch.

Inputs

NameRequiredDefaultDescription
sql-directoryyesDirectory with the migration files, relative to the repository root. Everything in it, subdirectories included, is uploaded.
output-pathyesPath of the SVG to create or update in the repository.
api-base-urlnohttps://schemadrawer.com/api/v1Base URL of the API.
migration-typenoFLYWAYThe migration tool the files are written for: FLYWAY, LIQUIBASE, PRISMA, DJANGO and the other MigrationType values.
database-typenoPOSTGRESQLPOSTGRESQL, MYSQL, MARIADB, MSSQL, ORACLE or SQLITE.
database-versionno18Version of the engine, one of those it is offered in.
user-idnoderived from the repository nameUUID identifying this repository at schemadrawer.com.
timeout-secondsno300How long to wait for the diagram before failing the job.
base-branchnocurrent branchBranch the pull request targets.
pr-branchnoschemadrawer/update-<run id>-<run attempt>Branch created for the pull request.
pr-titlenoUpdate schema diagramTitle of the pull request.
pr-bodynoa generic messageBody of the pull request.
commit-messagenochore: update schema diagramCommit message for the diagram file.
github-tokenyesToken used to push the branch and open the pull request; needs contents: write and pull-requests: write.

Outputs

NameDescription
pull-request-urlURL of the pull request that was opened; empty when there was nothing to commit.

Requirements

  • A runner with curl, jq, python3 and the gh CLI, all preinstalled on ubuntu-latest.
  • actions/checkout before the action, so that the repository is there to commit into.
  • permissions: contents: write and pull-requests: write.

Running the draw step by hand

The action is two bash scripts. The first one takes its inputs from the environment and runs anywhere, which makes it a handy way to draw a diagram from a laptop or from another CI system:

SQL_DIRECTORY=db/migration \
OUTPUT_PATH=docs/schema-diagram.svg \
MIGRATION_TYPE=FLYWAY DATABASE_TYPE=POSTGRESQL DATABASE_VERSION=18 \
scripts/draw.sh

It prints the files it uploads, the job id and where the diagram went. A failed migration ends with the migration tool's message and exit code 1.

Tips

  • Trigger on paths that cover your migrations, so the diagram is redrawn exactly when it can change.
  • Draw on the engine version you deploy to. If you support several, run the action in a matrix and write one SVG per engine.
  • Use the failing step as a check: a pull request that breaks a migration fails the workflow with the tool's own error, before anyone deploys it.

Put the diagram in the pipeline

One step, one pull request per schema change, and a README that is never out of date.