Webhook icon
WorkingDirectory icon
Clone icon
Commands icon
Docker icon
Script icon
Switch icon
SlackIncomingWebhook icon
Fail icon
Log icon

Database Schema Migration Safety and Destructive Change Gate with Atlas

Audit SQL migrations with Atlas to detect table drops, missing defaults, and concurrency locks before GitOps database deployment.

Categories
Infrastructure

Automates pre-deployment database migration verification using Ariga Atlas. Clones versioned SQL migration directories, dry-runs AST schema changes against an ephemeral dev database, and blocks destructive operations such as unbackfilled non-nullable columns, table drops, and exclusive table-locking index builds before production GitOps rollouts.

How it works

  1. Webhook Ingestion: Triggered via an authenticated event Webhook from GitHub Actions or GitLab CI whenever database migration files change on a pull request branch.
  2. Isolated Workspace Checkout: An io.kestra.plugin.core.flow.WorkingDirectory container task clones the target migration repository branch using io.kestra.plugin.git.Clone.
  3. Atlas Migration Linting: Executes arigaio/atlas:latest-alpine inside a Docker runner, calling atlas migrate lint against the specified --dev-url (e.g. SQLite in-memory or a staging database) to simulate schema changes and export diagnostic findings as structured JSON.
  4. Safety Analysis & Categorization: A Python script parses the Atlas lint report, categorizing diagnostics into destructive changes (DS101 dropped schema, DS102 dropped table, DS103 dropped column, MF103/MY101 non-null column without a default, MY130/PG301 incompatible type change requiring a rewrite) and concurrency/locking hazards (PG101/PG102 non-concurrent index operations, PG104/PG105/PG312 exclusive-lock constraint builds, MY132/MY137/MY147 MySQL table rebuilds).
  5. Admission Gate Routing: An io.kestra.plugin.core.flow.Switch evaluates the calculated verdict:
    • DESTRUCTIVE_SCHEMA_MUTATION: Dispatches an incident alert via io.kestra.plugin.slack.notifications.SlackIncomingWebhook and halts deployment via io.kestra.plugin.core.execution.Fail unless allow_destructive_changes is explicitly enabled.
    • CONCURRENCY_LOCK_HAZARD: Dispatches a lock hazard warning to the DBA team and prevents unindexed deployments.
    • MIGRATION_APPROVED: Logs verification metrics and approves the migration for production release.

What you get

  • Zero-Downtime Migration Assurance: Catches locking DDL operations (such as non-concurrent index builds) before they starve production query pools.
  • Accidental Data Loss Protection: Blocks dropped tables, dropped columns, and incompatible column mutations in continuous integration.
  • Developer Feedback Loop: Delivers exact SQL statements, diagnostic codes, and remediation instructions directly into Slack channels.
  • Audit Trail: Maintains an immutable record in Kestra of all evaluated migration files, timestamps, and safety approvals.

Who it's for

  • Platform & Database Engineers: Enforcing schema change management policies across distributed engineering teams.
  • DevOps Engineers: Preventing database-induced pipeline outages in GitOps and CI/CD deployment workflows.
  • Backend Developers: Gaining automated pre-merge safety feedback on complex database refactorings.

Why orchestrate this with Kestra

  • Declarative Quality Gating: Defines migration validation as versioned, self-documenting YAML instead of bespoke, fragile bash scripts in CI agents.
  • Stateful Branching: Combines WorkingDirectory, Git, Docker, and Switch tasks to manage cross-task file artifacts and multi-tier operational responses.
  • Unified Secret Governance: Centralizes database credentials, webhook keys, and notification tokens using Kestra namespace secrets.
  • Extensible Remediation: Easily chains downstream tasks such as automated pull request status updates, staging migrations, or Jira change requests.

Prerequisites

  • Docker container runner enabled on the Kestra worker executing the flow.
  • Access to pull the free, public arigaio/atlas:latest-alpine and python:3.11-slim container images.

Secrets

  • ATLAS_GATE_WEBHOOK_KEY: Shared secret authenticating inbound CI/CD webhook requests.
  • SLACK_WEBHOOK_URL: Incoming webhook URL for database deployment Slack alerts.

Quick start

  1. Store your ATLAS_GATE_WEBHOOK_KEY and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Provide your repository URL in git_repository_url and relative migration directory in migrations_dir.
  3. Trigger a manual test execution from the Kestra UI to lint recent migration files against the default SQLite dev engine.
  4. Enable pull_request_webhook to automatically gate database migrations in your CI/CD pipeline.

How to extend

  • Multi-Database Dialects: Point dev_database_url to a containerized PostgreSQL or MySQL instance to validate engine-specific constraints.
  • Automated Pull Request Review: Add io.kestra.plugin.github.pulls.Comment to publish lint diagnostics directly onto the GitHub pull request.
  • Downstream Migration Execution: Chain an atlas migrate apply task following MIGRATION_APPROVED to automatically promote safe changes to staging.
  • Custom Linting Policies: Mount an atlas.hcl configuration file to enforce custom naming conventions or table comment requirements.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.