New to Kestra?
Use blueprints to kickstart your first workflows.
Audit and prune inactive Neon Postgres preview branches from closed pull requests to reclaim storage and prevent branch quota exhaustion.
Modern engineering teams running serverless PostgreSQL on Neon spin up isolated database branches for preview environments on every pull request. However, when pull requests merge or close without deleting their database branch, preview environments linger indefinitely. Over time, projects exhaust their account branch quota (preventing new CI preview builds) and accumulate ongoing storage costs for abandoned data copies.
This blueprint provides an automated FinOps guard that queries the Neon Cloud Management REST API, discovers idle preview branches older than a configurable retention threshold, enforces a safe deletion ceiling, and cleans up stale branches with dry-run protection and double-check readback verification.
fetch_branches (io.kestra.plugin.core.http.Request) queries the Neon REST API for all branches in the target project.filter_stale_branches (io.kestra.plugin.core.output.OutputValues) evaluates branches using Pebble date math and jq filtering. It isolates branches matching inputs.preview_prefix, strictly excludes default and protected branches, and identifies those whose updated_at timestamp exceeds inputs.retention_hours.evaluate_stale_branches (io.kestra.plugin.core.flow.If) checks whether any stale branches require action.evaluate_dry_run_gate (io.kestra.plugin.core.flow.If) branches execution based on inputs.dry_run:dry_run: true, it logs the planned deletion list without mutating cloud resources.dry_run: false, prune_branches (io.kestra.plugin.core.flow.Loop) iterates sequentially over each branch with concurrencyLimit: 1 to dispatch DELETE requests to the Neon API.verify_readback (io.kestra.plugin.core.http.Request) performs an immediate post-deletion readback to verify that target branches are no longer present.notify_slack_summary (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches an operational summary card to Slack detailing the reclaimed branches and current project branch count.dry_run: true and protection for default and protected branches.max_prune_count, capping how many branches can be deleted per execution.Custom bash scripts and cron jobs querying cloud APIs often lack execution history, credential governance, and error handling. Running branch cleanup through Kestra provides unified secrets management for NEON_API_KEY, visual execution auditing, automated retries, and both scheduled and event-driven webhook execution directly linked to Slack notifications.
preview/).retention_hours buffer.concurrencyLimit: 1 on the deletion loop to avoid throttling during batch cleanups.NEON_API_KEY: Neon API Key generated from the Neon Console account settings.SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for alerting.WEBHOOK_KEY: Secret authentication key for the event-driven webhook trigger.NEON_API_KEY, SLACK_WEBHOOK_URL, and WEBHOOK_KEY in your Kestra namespace secrets.dry_run: true to review stale preview branches without deleting them.dry_run: false to enable active branch cleanup.daily_maintenance_schedule trigger for continuous automated pruning, or call pr_closed_webhook from your GitHub Actions workflow when a pull request closes.inputs.preview_prefix from a GitHub Actions webhook to trigger immediate branch deletion as soon as a pull request merges.core.execution.Fail if project branch usage exceeds 90% of your plan's branch limit.io.kestra.plugin.core.flow.Subflow to sweep multiple Neon projects across development and staging environments.