Webhook icon
Schedule icon
Log icon
Commands icon
Docker icon
If icon
Parallel icon
SlackIncomingWebhook icon
Pause icon

Destructive Database Migration Safety Gate

Pre-deployment database migration safety gate auditing DDL for exclusive table locks, pool pressure, and destructive operations in Kestra.

Categories
DataInfrastructure

Orchestrate an automated pre-deployment database migration safety gate that statically audits SQL and DDL scripts for destructive operations, table-rewrites, and exclusive locks, evaluates real-time connection pool pressure and replica lag, and halts high-risk schema changes with human-in-the-loop DBA sign-off before production deployment.

In production PostgreSQL and MySQL environments, running unvetted DDL statements, such as DROP COLUMN, ALTER TABLE ... NOT NULL without defaults, or index creation without CONCURRENTLY, triggers table-level exclusive locks (AccessExclusiveLock) that freeze user queries and cause immediate service outages. This blueprint establishes a deterministic safety gate:

  1. Static DDL Risk Analysis (ddl_risk_and_lock_analyzer): Scans migration SQL scripts for non-concurrent indexes, table drops, and column rewrites that cause exclusive table locks.
  2. Cluster Health & Pool Inspection (check_database_health_metrics): Evaluates active connection pool usage and replication lag to ensure migrations do not run during traffic spikes.
  3. Automated Safety Gate (If): Permits zero-downtime, non-blocking migrations to execute automatically if the lock risk score remains below the threshold (max_lock_risk_score).
  4. Human-in-the-Loop Governance (Pause): Automatically pauses risky or destructive migrations for up to 24 hours (pause_for_lead_dba_signoff), requiring DBA sign-off before proceeding.
  5. Slack Notifications: Dispatches real-time approval notifications or high-risk lock alerts directly to engineering and database team channels.

How it works

  1. Ingestion Triggers:
    • The inbound_migration_webhook trigger (io.kestra.plugin.core.trigger.Webhook) allows CI/CD pipelines (GitHub Actions, GitLab CI, ArgoCD) to initiate pre-migration safety checks.
    • The scheduled_migration_window trigger runs during off-peak maintenance hours.
  2. Static Lock Inspection (ddl_risk_and_lock_analyzer):
    • Runs inside a containerized Python runner (python:3.11-slim) to parse DDL statements and compute an objective lock risk score.
  3. Connection Pool Verification (check_database_health_metrics):
    • Verifies that connection pool capacity is below 80% saturation and replica lag is minimal.
  4. Gated Remediation & DBA Sign-Off (evaluate_migration_safety_gate):
    • Non-blocking DDL receives immediate Slack clearance. High-risk migrations trigger a 24-hour Kestra Pause gate for DBA review.

What you get

  • Zero-downtime database deployment guardrails preventing accidental table locks.
  • Automated detection of missing CONCURRENTLY index declarations and table rewrites.
  • Real-time connection pool saturation validation before schema migrations apply.
  • Native human-in-the-loop pause governance for database administrators.
  • Real-time Slack notifications with actionable DDL risk scorecards.

Who it's for

  • Database Administrators (DBAs) and Platform Engineers managing mission-critical databases.
  • DevOps and Backend Engineers integrating automated migration gates into CI/CD pipelines.
  • Tech Leads safeguarding production PostgreSQL and MySQL clusters against accidental downtime.

Why orchestrate this with Kestra

Safe schema migrations require polyglot coordination: static SQL parsing, live connection telemetry inspection, webhook listeners, conditional execution gates, and human sign-off mechanisms. Kestra orchestrates this full stack declaratively with Docker isolation, structured outputs, conditional branching, and pause governance without custom daemons.

Prerequisites

  • Docker daemon accessible to Kestra for containerized execution.
  • Slack Incoming Webhook URL configured in Kestra secrets (if Slack alerts are enabled).

Secrets

  • MIGRATION_WEBHOOK_KEY: Secret authentication key for inbound CI/CD migration webhooks.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint for team alerts.

Inputs

Name Type Default Description
database_name STRING production_core_db Target database instance identifier.
migration_file_name STRING V24__add_billing_partition.sql Pending SQL migration file under evaluation.
target_engine SELECT PostgreSQL Database engine architecture (PostgreSQL, MySQL).
max_lock_risk_score INT 25 Maximum acceptable lock risk score (0 to 100).
require_dba_approval BOOL true Enforces Kestra Pause task for high-risk migrations.

Quick start runbook

  1. Configure secrets MIGRATION_WEBHOOK_KEY and SLACK_WEBHOOK_URL in your Kestra namespace.
  2. Trigger the flow manually from the Kestra UI to witness DDL risk parsing and health metric verification.
  3. If lock risk exceeds 25, click Resume on the interactive Pause task in Kestra to simulate Lead DBA sign-off.
  4. Connect the inbound webhook URL to your GitHub Actions or Flyway migration pipeline.

How to extend

  • Connect Flyway or Liquibase tasks to automatically apply approved migrations upon DBA sign-off.
  • Integrate PostgreSQL query tasks (pg_stat_statements) to benchmark query plan performance before and after migrations.
  • Integrate PagerDuty to alert on-call DBAs immediately if a migration locks production tables.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.