How to Separate Dev and Prod Warehouses in CI
A separate CI target on a dev database keeps pull request runs off the production warehouse entirely.
Define distinct ci and prod targets in profiles.yml, then select the target by branch so PRs use dev and main uses prod.
Steps
- Add
ciandprodoutputs with different databases and warehouses. - Use the
citarget onpull_request. - Gate the
prodtarget behind a protected environment on main.
profiles.yml
profiles.yml
analytics:
outputs:
ci:
type: snowflake
database: DEV
warehouse: DEV_WH
schema: "pr_{{ env_var('GITHUB_RUN_ID', 'local') }}"
prod:
type: snowflake
database: PROD
warehouse: PROD_WH
schema: analyticsWorkflow
.github/workflows/ci.yml
jobs:
pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- run: dbt build --target ci
deploy:
if: github.ref == 'refs/heads/main'
environment: production
runs-on: ubuntu-latest
steps:
- run: dbt build --target prodGotchas
- Grant the CI role write access to dev only, never to the prod database.
- A per-PR schema keeps concurrent pull requests from colliding in the dev database.
Related guides
How to Use OIDC for Warehouse Credentials in CIAuthenticate CI to a cloud warehouse with short-lived OIDC tokens instead of long-lived passwords, using conf…
How to Run dbt build and Tests on Pull Requests in CIRun dbt build on every pull request in GitHub Actions so models compile, run, and pass their tests against a…