SchemaLens in Your CI/CD Pipeline
Step-by-step setup for GitHub Actions and GitLab CI. Catch migration risks before they merge.
Run SchemaLens in your CI/CD pipeline to automatically diff database schemas on every pull request. Get a markdown report of breaking changes, dropped columns, and missing indexes posted directly to your PR — before it reaches production.
No database connection required. Works with any SQL dump or migration file.
The cheapest place to fix a migration is before it ships.
Automatically flag dropped tables, removed columns, NOT NULL without defaults, and type narrowing. Stop dangerous migrations at the PR gate.
SchemaLens posts a formatted markdown diff report as a PR comment. Reviewers see exactly what changed — tables, columns, constraints, indexes — without leaving GitHub.
A single Node.js file with no npm install required. Drop ci/schemalens-diff.js into your repo and run it in any CI platform that supports Node 18+.
PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, and Oracle. Pass --dialect=postgres (or mysql, sqlite, mssql, oracle) and get dialect-aware diff reports.
SchemaLens understands CREATE TABLE structure. It compares columns, types, defaults, constraints, indexes, triggers, and views — not just lines of text.
Export diff reports as Markdown for human review or JSON for programmatic pipeline gates. Fail the build only when breaking changes are detected.
Add this workflow to .github/workflows/schema-diff.yml to diff schemas on every SQL-related PR.
name: Schema Diff
on:
pull_request:
paths:
- 'db/schema.sql'
- 'migrations/*.sql'
- '**/*.sql'
jobs:
schema-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run SchemaLens Diff
id: diff
run: |
git show origin/\${{ github.base_ref }}:db/schema.sql > /tmp/schema_base.sql 2>/dev/null || echo "-- No base schema" > /tmp/schema_base.sql
node ci/schemalens-diff.js /tmp/schema_base.sql db/schema.sql --dialect=postgres --format=markdown --output=/tmp/report.md
echo "report<> \$GITHUB_OUTPUT
cat /tmp/report.md >> \$GITHUB_OUTPUT
echo "EOF" >> \$GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const report = `\${{ steps.diff.outputs.report }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## SchemaLens Diff Report\n\n' + report
});
Add this job to .gitlab-ci.yml to run schema diffs on merge requests.
schema_diff:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- db/schema.sql
- migrations/*.sql
image: node:20-alpine
script:
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git show origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME:db/schema.sql > /tmp/schema_base.sql 2>/dev/null || echo "-- No base schema" > /tmp/schema_base.sql
- node ci/schemalens-diff.js /tmp/schema_base.sql db/schema.sql --dialect=postgres --format=markdown --output=schema_diff_report.md
artifacts:
paths:
- schema_diff_report.md
expire_in: 1 week
Copy ci/bitbucket-pipelines.yml from this repo or use the template below.
image: node:20
pipelines:
pull-requests:
'**':
- step:
name: Schema Diff
script:
- git fetch origin $BITBUCKET_PR_DESTINATION_BRANCH
- git show origin/$BITBUCKET_PR_DESTINATION_BRANCH:db/schema.sql > /tmp/schema_base.sql 2>/dev/null || echo "-- No base schema" > /tmp/schema_base.sql
- node ci/schemalens-diff.js /tmp/schema_base.sql db/schema.sql --dialect=postgres --format=markdown --output=schema_diff_report.md
artifacts:
- schema_diff_report.md
Use the same diff engine locally or in any CI platform.
# Download the CLI
curl -O https://schemalens.tech/ci/schemalens-diff.js
# Basic usage
node ci/schemalens-diff.js old_schema.sql new_schema.sql
# With options
node ci/schemalens-diff.js old_schema.sql new_schema.sql \
--dialect=postgres \
--format=markdown \
--output=diff_report.md
# JSON output for programmatic gates
node ci/schemalens-diff.js old_schema.sql new_schema.sql \
--dialect=mysql \
--format=json \
--output=diff.json
Step-by-step setup for GitHub Actions and GitLab CI. Catch migration risks before they merge.
Learn how to catch dropped columns, missing indexes, and type changes before they cause incidents.
A practical guide to schema review workflows for teams of any size.
Copy the workflow template, drop in the CLI script, and start catching migration risks before they hit production. Free forever for open source and small teams.
Try SchemaLens FreeNo signup required. No data leaves your browser.