Skip to content

CI/CD Integration

pgmold includes a GitHub Action for schema CI: migration plan comments, drift detection, PR auto-labeling, and warning annotations.

- uses: fmguerreiro/pgmold/.github/actions/drift-check@main
with:
schema: sql:schema/
database: db:${{ secrets.DATABASE_URL }}
target-schemas: public,auth
  • Live database mode: Requires database. Generates a migration plan, posts it as a PR comment, and optionally checks for drift.
  • SQL-to-SQL baseline mode: Requires baseline. Diffs schema against a baseline SQL file — no live database needed.
InputRequiredDefaultDescription
schemayesSchema source(s), space-separated
databasenoPostgreSQL connection string
baselinenosql:path/to/baseline.sql for SQL-to-SQL diff
target-schemasnopublicComma-separated PostgreSQL schemas
fail-on-driftnotrueFail if drift detected
plan-commentnotruePost migration plan as PR comment
drift-checknotrueRun drift detection
auto-labelnotrueAdd database-schema label on changes
OutputDescription
has-driftWhether drift was detected (true/false)
expected-fingerprintExpected schema fingerprint from SQL files
actual-fingerprintActual schema fingerprint from database
reportFull JSON drift report
plan-jsonFull plan JSON output
statement-countNumber of SQL statements in the plan
has-destructiveWhether the plan contains destructive operations
comment-idID of the PR comment posted or updated
name: Schema Check
on:
pull_request:
jobs:
schema-ci:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: fmguerreiro/pgmold/.github/actions/drift-check@main
with:
schema: sql:schema/
database: db:${{ secrets.DATABASE_URL }}
target-schemas: public,auth

For local or custom CI environments, use the drift command directly:

Terminal window
pgmold drift -s sql:schema/ -d postgres://localhost/mydb --json

Output:

{
"has_drift": true,
"expected_fingerprint": "abc123...",
"actual_fingerprint": "def456...",
"differences": ["AddColumn { schema: \"public\", table: \"users\", ... }"]
}

Drift detection compares SHA256 fingerprints of normalized schemas. Any difference triggers drift. Exit code is non-zero when drift is detected.