🚀 One config, zero friction

Copy this into your repo as azure-pipelines.yml or let the wizard auto-detect your schema files.

# azure-pipelines.yml
# SchemaLens Azure DevOps Pipeline
# Compare database schemas on every pull request and post the diff as a PR comment.
# Docs: https://schemalens.tech/azure-devops-schema-diff.html

trigger:
  branches:
    include:
      - main

pr:
  paths:
    include:
      - 'db/schema.sql'
      - 'migrations/*.sql'
      - '**/*.sql'

variables:
  SCHEMA_OLD_PATH: 'db/schema.sql'
  SCHEMA_NEW_PATH: 'db/schema.sql'
  DIALECT: 'postgres'
  FAIL_ON_BREAKING: 'false'
  POST_PR_COMMENT: 'true'

pool:
  vmImage: 'ubuntu-latest'

steps:
  - checkout: self
    fetchDepth: 0
    displayName: 'Checkout PR branch'

  - task: NodeTool@0
    inputs:
      versionSpec: '20.x'
    displayName: 'Install Node.js'

  - script: |
      set -e
      echo "Running SchemaLens schema diff..."
      git fetch origin $(System.PullRequest.TargetBranch)
      git show origin/$(System.PullRequest.TargetBranch):$(SCHEMA_OLD_PATH) > /tmp/schema_base.sql 2>/dev/null || echo "-- No base schema found" > /tmp/schema_base.sql
      node ci/schemalens-diff.js /tmp/schema_base.sql $(SCHEMA_NEW_PATH) --dialect=$(DIALECT) --format=markdown --output=/tmp/schema_diff_report.md
      cat /tmp/schema_diff_report.md
    displayName: 'SchemaLens Schema Diff'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))

  - task: PublishBuildArtifacts@1
    inputs:
      PathToPublish: '/tmp/schema_diff_report.md'
      ArtifactName: 'schema-diff-report'
    displayName: 'Publish diff report'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))

  # Optional: post the report as a PR comment using the Azure DevOps REST API.
  # Requires "Contribute to pull requests" permission for the build service.
  - script: |
      set -e
      REPORT=$(cat /tmp/schema_diff_report.md)
      BODY="## SchemaLens Schema Diff Report\n\n$REPORT"
      curl -s -X POST \
        "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullRequests/$(System.PullRequest.PullRequestId)/threads?api-version=7.0" \
        -H "Authorization: Bearer $(System.AccessToken)" \
        -H "Content-Type: application/json" \
        -d "{\"comments\":[{\"commentType\":1,\"content\":\"$BODY\"}],\"status\":1}"
    displayName: 'Post PR comment'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['POST_PR_COMMENT'], 'true'))

  - script: |
      set -e
      BREAKING=$(node ci/schemalens-diff.js /tmp/schema_base.sql $(SCHEMA_NEW_PATH) --dialect=$(DIALECT) --format=json | node -e "let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>{const j=JSON.parse(d);process.stdout.write(String((j.riskScore&&j.riskScore.breaking?j.riskScore.breaking.length:0)||(j.breakingChanges?j.breakingChanges.length:0)));}"))
      echo "Breaking changes: $BREAKING"
      if [ "$BREAKING" != "0" ]; then
        echo "##vso[task.logissue type=error]Breaking schema changes detected"
        exit 1
      fi
    displayName: 'Fail on breaking changes'
    condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), eq(variables['FAIL_ON_BREAKING'], 'true'))
⚡ Generate my Azure DevOps config Download azure-pipelines.yml

💬 What your team sees in every pull request

SL
SchemaLens Bot
commented 2 minutes ago

🔍 SchemaLens Schema Diff Report

🟢 Tables Added1
🔴 Tables Removed0
🟡 Tables Modified2
⚠️ Breaking Changes1
📊 Risk Score42/100 (Medium)
ALTER TABLE users
  ADD COLUMN email_verified_at TIMESTAMP;

Why Azure DevOps teams use SchemaLens

🛡️ Block breaking changes before merge

Dropped columns, removed indexes, and altered constraints fail the pipeline before they reach production.

💬 PR thread comments

Reviewers see the diff summary directly in the Azure DevOps pull request — no external dashboards needed.

📦 Published artifacts

Every build publishes a markdown report for compliance docs, audits, or offline review.

⏭️ Path filters

The pipeline only runs when .sql files change, so unrelated PRs don't waste agent time.

Get it running in 3 steps

1

Open the Azure DevOps wizard

The wizard auto-detects SQL files from your public GitHub repo and selects the right dialect for your Azure DevOps pipeline.

2

Copy the generated config

Paste it into azure-pipelines.yml at the root of your repo. Adjust SCHEMA_PATH if your schema lives elsewhere.

3

Open your next pull request

SchemaLens compares the target branch schema against your branch and posts the result as a PR comment.

Ready to add schema diff to your Azure DevOps repo?

It takes 60 seconds and works with PostgreSQL, MySQL, SQLite, SQL Server, and Oracle.

⚡ Generate Azure DevOps config Other platforms