Webhook icon
Commands icon
Return icon
Switch icon
Log icon
SlackIncomingWebhook icon
Fail icon

Squawk Postgres Migration Destructive-Change Gate

Block PostgreSQL migrations with irreversible or breaking changes while only warning on locking-risk changes.

Categories
Data

A migration gate that fails on every lint finding trains teams to bypass it, because plenty of Squawk's findings (an index created without CONCURRENTLY, a nested transaction) are locking-risk warnings a team can often still ship carefully, not reasons to block a release. This blueprint lints a pending migration with Squawk, splits its findings into "irreversible or breaks running code" and "locking or availability risk," and only fails the execution outright on the first group, so chaining this flow as a migration gate blocks exactly the changes nobody should ship unreviewed while the second group pages Slack for a human read instead of blocking indefinitely.

How it works

  1. lint_on_pr_webhook (io.kestra.plugin.core.trigger.Webhook) lets a CI pipeline POST a pending migration file to this flow directly as part of a pull request check. fetchType: STORE streams that POST body into Kestra's internal storage and exposes it as trigger.uri, a safe file reference, rather than as raw trigger.body text, which the trigger's own documentation flags as untrusted input unsafe to interpolate into a script task's commands. Running this flow manually or as a Subflow instead uses the migration_file input, the same kind of safe file reference.
  2. lint_migration (io.kestra.plugin.scripts.shell.Commands) runs Squawk's own ghcr.io/sbdchd/squawk container against whichever of those two is defined, with --format json, redirecting its output to report.json regardless of Squawk's own exit code (a non-zero exit on findings is expected behavior, not a failure this flow should abort on).
  3. classify_migration_safety (io.kestra.plugin.core.debug.Return) checks whether report.json was produced; if not, UNREACHABLE. Otherwise it reads the file with Kestra's read() function and counts, by rule_name, how many findings are in the destructive/breaking set (every ban-drop-* rule, a column/table/object rename, a column type change, a cascading truncate, or a SQL syntax error) versus the locking/availability set (an unguarded NOT NULL addition, a non-concurrent index operation, nested transactions, missing timeout guards). This split is deliberate: Squawk's own level field reports every rule violation as Warning regardless of how dangerous the rule is, confirmed directly from Squawk's reporter.rs source, where level: Error is reserved for SQL syntax errors only, so rule_name is the only signal that actually distinguishes severity here, not level.
  4. route_by_migration_safety (io.kestra.plugin.core.flow.Switch) branches on that string: PASS logs a quiet confirmation, WARN pages Slack with the specific locking-risk rule names but lets the execution succeed, BLOCK pages Slack with the specific destructive rule names and then runs fail_gate (io.kestra.plugin.core.execution.Fail) to deliberately fail the execution, and UNREACHABLE pages Slack separately.
  5. log_audit_status records a status line whenever the execution reaches it, i.e. every outcome except BLOCK, which fails before reaching this task by design.
  6. The errors block fires both for a genuine flow break and, intentionally, every time fail_gate fires, a chained parent pipeline sees either case as the same FAILED execution and stops.

What you get

  • A migration gate that distinguishes "irreversible or silently breaks a running application" from "risks a lock or a maintenance window, but is frequently still shippable," instead of a blanket finding-count threshold that trains people to ignore it.
  • A hard stop: fail_gate makes the execution itself FAILED on a destructive finding, so a parent flow using this as a Subflow task before migrate apply-style tasks is actually blocked, not just notified into a channel someone might not read before merging.
  • A status output (PASS / WARN / BLOCK / UNREACHABLE) you can also read directly if you prefer branching in the caller instead of relying on failure propagation.
  • A documented, source-verified correction of a subtle Squawk behavior (every finding reports as level: Warning) that would otherwise make a naive level-based gate useless.

Who it's for

  • Platform and database teams enforcing a PostgreSQL migration review policy who want CI to fail loudly on an actual data-loss risk, not on every style nit Squawk reports.
  • Teams who have tried a naive "any finding, fail" gate and abandoned it because locking-risk warnings made it fail on changes the team deliberately decided to ship anyway.

Why orchestrate this with Kestra

Squawk produces the findings; nothing in the CLI itself enforces a policy or blocks a deploy pipeline on your terms. Kestra turns that output into an actual pass/fail decision with a real execution-history trail of exactly which rule names triggered a block versus a warning, and Fail gives a parent pipeline a real signal to stop on instead of a Slack message it has to notice in time.

Prerequisites

  • Docker available to the Kestra worker, to run Squawk's own ghcr.io/sbdchd/squawk image, no database connection, server, or account is required; Squawk lints the SQL text itself.
  • A pending .sql migration file, either uploaded as migration_file for a manual or Subflow run, or POSTed by a CI pipeline to the lint_on_pr_webhook URL for an event-driven run.
  • A Slack incoming webhook URL.

Secrets

  • MIGRATION_LINT_WEBHOOK_KEY: the key segment of the webhook URL (.../executions/webhook/{namespace}/{flowId}/{key}). Only needed if you enable lint_on_pr_webhook; a manual or Subflow run using migration_file does not need it.
  • SLACK_WEBHOOK_URL: Slack incoming webhook used for the WARN alert, the BLOCK alert, the unreachable alert, and the flow-failure alert.
  • OSS note: if your Kestra instance reads secrets from environment variables instead of a secrets backend, set SECRET_MIGRATION_LINT_WEBHOOK_KEY and SECRET_SLACK_WEBHOOK_URL as base64, for example echo -n "<your-value>" | base64.

Quick start

  1. Add the SLACK_WEBHOOK_URL secret, and the MIGRATION_LINT_WEBHOOK_KEY secret if you plan to enable the webhook.
  2. Write a test migration containing both a DROP COLUMN and an ADD COLUMN ... NOT NULL without a default, to exercise the BLOCK and WARN outcomes in one file (or split them into two runs).
  3. Upload that file as migration_file, run the flow manually, and confirm status matches what you expect.
  4. Either enable lint_on_pr_webhook and have your CI pipeline curl --data-binary @migration.sql the webhook URL on each pull request, or wire a Subflow task pointing at this flow into your deployment pipeline immediately before the task that applies migrations.

How to extend

  • Add a pg_version input and pass it through as Squawk's --pg-version flag once you have confirmed the exact flag syntax against the version you run, to make version-specific rules (e.g. identity columns) accurate for your cluster.
  • Store each BLOCK's rule names in a KV store keyed by migration filename, to build a team-wide record of what got stopped and why.
  • Add a second Slack channel specifically for the WARN case, separate from BLOCK, so on-call is not paged for changes that do not need an on-call response.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.