Skip to content

CI/CD Integration

Every dbsh command supports --json for machine-readable output and deterministic exit codes.

JSON output

bash
# Validate
dbsh validate --json
# { "success": true, "scriptsChecked": 16, "errors": [], "warnings": [] }

# Deploy
dbsh migrate --json
# { "success": true, "applied": 3, "appliedMigrations": ["001", "002", "003"], ... }

# Status
dbsh status --json
# { "success": true, "applied": 3, "pending": 1, "failed": 0, ... }

Exit codes: 0 = success, 1 = error.

GitHub Actions

yaml
name: Database Migration

on:
  push:
    branches: [main]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.0.x'
      - run: dotnet build dbsh.slnx -c Release
      - run: dotnet test dbsh.slnx -c Release --no-build
      - run: dotnet run --project src/dbsh.CLI -- validate --json

  deploy-dev:
    needs: validate
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.0.x'
      - run: dotnet run --project src/dbsh.CLI -- migrate -e development --yes --json
        env:
          DB_CONNECTION_STRING: ${{ secrets.DEV_DB_CONNECTION_STRING }}

Azure DevOps

yaml
steps:
  - script: dotnet run --project src/dbsh.CLI -- validate --json
    displayName: 'Validate migrations'

  - script: dotnet run --project src/dbsh.CLI -- migrate -e development --yes
    displayName: 'Deploy to dev'
    env:
      DB_CONNECTION_STRING: $(DEV_DB_CONNECTION_STRING)

Best practices

PracticeWhy
Run validate firstFast, no database needed, catches issues early
Use --jsonStructured output for logging and parsing
Use --yesSkip interactive prompts in automation
Store secrets in secrets/variable groupsNever commit connection strings
Use --in-memory for validation-only stepsNo database dependency in CI
Promote through environmentsdev -> staging -> prod with approvals at each gate
Use --force sparinglyBypasses deployment window and safety checks

Exit codes

CodeMeaning
0Success
1Error (migration failed, validation error, lock not acquired, etc.)

Use these in CI conditionals:

yaml
- run: dotnet run --project src/dbsh.CLI -- validate --json
  id: validate

- run: echo "Validation passed"
  if: steps.validate.outcome == 'success'

Released under the MIT License.