New to Kestra?
Use blueprints to kickstart your first workflows.
Run dbt transformations in staging, verify models, and atomically swap schemas on PostgreSQL with Kestra for zero-downtime, safe warehouse ELT.
Running dbt transformations directly against production database schemas introduces substantial operational risk. If an upstream batch contains malformed records or a downstream model fails midway through dbt build, production marts are left in a half-mutated, corrupted state that immediately impacts live BI dashboards and user queries.
This blueprint orchestrates a zero-downtime blue-green schema deployment pattern for dbt Core on PostgreSQL. All models and tests are compiled and executed strictly inside an isolated staging schema. Once model materialization and assertions pass verification, Kestra executes an atomic schema swap in a single transaction block. If any step fails, the staging schema is dropped and live production tables remain completely untouched.
prepare_staging_schema (io.kestra.plugin.jdbc.postgresql.Queries) drops any previous staging schema and creates a clean, isolated schema environment.run_dbt_staging (io.kestra.plugin.core.flow.WorkingDirectory) clones the Git repository and executes dbt deps and dbt build targeting the staging schema inside an isolated container.verify_staging_models (io.kestra.plugin.jdbc.postgresql.Query) queries PostgreSQL catalog metadata to verify that tables were successfully materialized in staging.evaluate_swap_gate (io.kestra.plugin.core.flow.If) checks that materialized tables exist and dry_run is false. When approved, atomic_schema_swap performs an instant transactional rename:notify_swap_success.errors block intercepts any failure during staging execution, purges the incomplete staging schema via cleanup_staging_on_error, and notifies Slack that production was protected.Coordinating blue-green warehouse deployments across Git clones, containerized dbt CLI runs, multi-statement database DDL transactions, and conditional alerting requires brittle bash glue when built manually. Kestra provides declarative task sequencing, native container runners, transactional SQL execution, and dedicated failure recovery handlers in a single reproducible workflow.
ALTER SCHEMA ... RENAME requires an AccessExclusiveLock on the schema. If long-running analytical queries are executing in the live schema, the rename will queue behind them. Set statement_timeout or lock_timeout in PostgreSQL if strict cutover windows are required.{{ ref(...) }} rather than hardcoding static database schema names, so models resolve dynamically to the staging target.CREATE, DROP, and RENAME schemas.POSTGRES_PASSWORD: Password for the PostgreSQL connection user.SLACK_WEBHOOK_URL: Webhook URL for dispatching deployment notifications.DBT_WEBHOOK_KEY: Secret authentication key for external CI trigger dispatch.POSTGRES_PASSWORD and SLACK_WEBHOOK_URL in your Kestra namespace secrets.postgres_host, postgres_db, and schema names in the flow inputs.dry_run: true to verify dbt model building in staging without mutating live tables.dry_run: false to execute the full blue-green promotion.dbt snapshot or custom analytical seed steps before promotion.