Use dbt state:modified selector and slim CI to run only changed models and their downstream dependents in pull request pipelines

domain: docs.getdbt.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. 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)
  2. 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
  3. 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
  4. 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
  5. 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

Related routes

Configure dbt model deferral and state:modified to speed up CI runs against a production manifest
docs.getdbt.com · 5 steps · unrated
Build an affected-only CI pipeline for a Turbo or Nx monorepo with change detection
nx.dev · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans