Generate and store a production manifest by running dbt docs generate or dbt compile in your production environment after each successful main branch deploy; save the resulting target/manifest.json as an artifact (e.g., in S3 or a CI artifact store)
In your CI pipeline, download the production manifest to a known path (e.g., prod-manifest/manifest.json) before the dbt run step; then run dbt build --select state:modified+ --state prod-manifest/ to build only models modified in the PR and all their downstream dependents
Add --defer --state prod-manifest/ to reuse production results for unmodified upstream models rather than running them; this allows incremental CI runs where only changed models are executed while downstream models still receive upstream data from production
Configure the CI environment to use a separate schema (e.g., ci_<PR_number>) so CI runs do not overwrite production tables; use the target.schema variable in dbt_project.yml to namespace CI artifacts
After CI completes, clean up CI schemas automatically using a post-run hook or a separate cleanup job that drops schemas matching the ci_ prefix older than a certain age
Known gotchas
The state:modified selector compares model SQL and configuration hashes between the PR branch and the production manifest; purely cosmetic changes (comments, whitespace) do not trigger re-runs, but any functional SQL change does — ensure your production manifest is always up to date or you may miss detecting changes
dbt defer requires that the production manifest and catalog were generated from the same dbt project version; if the production manifest is from an older dbt version than the CI environment, deserialization errors can occur — version-pin your dbt installation across environments
CI schemas created with state:modified may be missing models that are upstream of the modified models but were deferred from production; downstream models in the same CI run reference production data via defer, but tests that check cross-model relationships may yield false results if production data differs from what the PR would produce
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp