New to Kestra?
Use blueprints to kickstart your first workflows.
Diff data contracts against database tables, generate backward-compatible SQL migrations and dbt models with AI, and validate syntax in Kestra.
Data contracts define explicit schema, SLA, and semantic expectations between upstream data producers (application microservices, event streams) and downstream analytics warehouses. As business domains evolve, producers introduce new fields, adjust constraints, or evolve data structures. When schema evolution occurs unannounced, downstream ingestion pipelines crash, dbt models fail to build, and analytics dashboards corrupt.
Traditional remediation requires data engineers to manually inspect database catalogs, write boilerplate
ALTER TABLE SQL statements, update corresponding dbt schema.yml model files, and open pull requests by hand.
This manual toil causes pipeline downtime and slows down data release velocity.
This blueprint automates the complete data contract enforcement and evolution lifecycle. It ingests declarative
contract definitions, discovers live table metadata from PostgreSQL catalogs, computes structured schema diffs,
and leverages Kestra's AI plugin with Google Gemini to synthesize safe, backward-compatible SQL migrations
and updated dbt model documentation. It automatically verifies generated migration syntax within a transactional
dry-run (BEGIN ... ROLLBACK) on PostgreSQL before publishing downloadable artifacts and Slack notifications.
inspect_target_table_schema (io.kestra.plugin.jdbc.postgresql.Query) queries information_schema.columns
on the target PostgreSQL database to inspect existing column names, data types, nullability, and default expressions.compute_contract_diff (io.kestra.plugin.scripts.python.Script) cross-references the live database schema
against the authoritative data_contract specification in Python, identifying newly added fields, type evolutions,
and deprecated columns.evaluate_contract_evolution (io.kestra.plugin.core.flow.If) branches on detected drift:log_contract_in_sync confirms complete contract alignment.generate_migration_and_dbt_models (io.kestra.plugin.ai.completion.ChatCompletion) prompts Google Gemini
with strict JSON schema to generate idempotent, non-locking ALTER TABLE SQL statements and formatted dbt model YAML.validate_migration_syntax (io.kestra.plugin.jdbc.postgresql.Queries) executes the generated SQL within
a transactional dry-run (BEGIN; ... ROLLBACK;) against PostgreSQL, confirming compiler syntax validity without
mutating production data.persist_migration_sql, persist_dbt_schema, and persist_migration_summary (io.kestra.plugin.core.storage.Write)
store the generated migration code and documentation in Kestra internal storage.notify_slack_summary dispatches an operational card to Slack with the migration preview and artifact download links.schema.yml model specifications with column descriptions and tests ready for version control.Data Engineers, Analytics Engineers, and Platform Architects implementing Data Contracts and Data Mesh architectures.
Coordinating data contract enforcement requires bridging relational database catalogs, contract JSON schemas, LLM generation with structured output schemas, transactional compiler validation, and artifact storage. Fragile ad-hoc CLI scripts lack execution tracking, expose database secrets, and cannot provide visual execution audits. Kestra unifies SQL discovery, Python computation, Google Gemini AI tasks, and artifact persistence into an auditable, reusable pipeline.
deprecated rather than generating DROP COLUMN statements, preventing
accidental data loss.ALTER TABLE operations on multi-gigabyte tables can block concurrent
readers and writers. Ensure added columns use PostgreSQL 11+ fast-default additions (ADD COLUMN ... DEFAULT ...)
rather than running full-table rewrites.BEGIN ... ROLLBACK to ensure zero unintended
modifications occur during dry-run validation.POSTGRES_PASSWORD: Administrative password for target PostgreSQL database connection.GEMINI_API_KEY: API key for Google Gemini AI completion tasks.SLACK_WEBHOOK_URL: Slack incoming webhook URL for contract notifications.CONTRACT_WEBHOOK_KEY: Secret authentication key for Git-triggered contract webhooks.POSTGRES_PASSWORD, GEMINI_API_KEY, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.orders table.contract_webhook_trigger to your Git repository to trigger automated migration generation upon contract updates.io.kestra.plugin.core.http.Request.dbt run tasks to execute models immediately following migration cutover.