| title | ADR 0003: Preview environment CI pattern | ||
|---|---|---|---|
| description | Zero-copy preview environments in CI for safe warehouse change validation. | ||
| product | drover-sqlforge | ||
| audience | platform-operator | ||
| doc_type | adr | ||
| topics |
|
||
| surface | repo-docs |
Status: Accepted
Date: 2026-05-22
Contexts: CONTEXT.md
Pull requests that change models or metrics need isolated validation on real warehouse data without writing to prod. SQLForge supports environments (named plan/apply targets), zero-copy isolation on ClickHouse, and a composite GitHub Action (action.yml) that:
- Creates a preview environment named
pr_{number}with base environmentprod(configurable). - Runs
sqlforge planand comments output on the PR. - Runs
sqlforge applywithCI=true(non-TTY).
Alternatives considered:
- Plan-only CI — post execution plan on PR; apply waits for human approval in console or separate workflow.
- Shared staging env per branch — reuse
staginginstead of per-PR env names; risk cross-PR contamination. - Physical full copy — clone prod tables without zero-copy; higher cost and time.
- No CI integration — manual
sqlforge planlocally only.
- Preview environment:
pr_{pull_request_number}(or explicitenvironmentinput). - Base environment (CI): defaults to
prod— the lineage parent for warehouse schema creation and zero-copy isolation where supported. - Each PR gets an isolated environment and warehouse schema (
sqlforge__pr_*), not shared staging unless configured.
The composite action in action.yml runs plan then apply automatically:
| Step | Purpose |
|---|---|
sqlforge plan |
Produce execution plan; comment on PR when github_token provided |
sqlforge apply |
Materialize changed and impacted models into the preview environment |
CI=true disables interactive TUI during apply.
config_dir defaults to . (project root relative to checkout).
CI apply gate — policy where CI posts plan only and apply requires a follow-up approval — is not the v1 default. Teams that need it can:
- split workflows (plan job + manual
workflow_dispatchapply), or - add a future
apply: falseinput on the composite action.
Document as deferred in glossary; do not block current action on gate UX.
- Warehouse credentials come from the CI secret store /
.envexpansion insqlforge.yml— same as local data engineers. - Project state (
.sqlforge/state.db) is ephemeral in CI runners; preview environment state is recreated per run unless cached by the platform.
Positive
- PR authors and reviewers see structural diffs before merge; isolated data plane reduces prod risk.
- Aligns with zero-copy isolation differentiator on ClickHouse.
- Reuses standard plan / apply vocabulary from
CONTEXT.md.
Negative
- Automatic apply on every PR sync may be too aggressive for large warehouses or costly models—teams may need plan-only forks until CI apply gate ships.
- Non-ClickHouse warehouse connections may not get true zero-copy; preview envs still work but may be slower/more expensive.
- Orphan preview environments (
pr_*) need operational cleanup policies outside SQLForge v1.
Follow-ups
- Add
apply: false(orplan_only: true) input toaction.yml. - Document teardown job (
env destroyor warehouse DDL) for stalepr_*schemas. - Link from
examples/github-actions/pr-preview.ymlto this ADR.
- Glossary:
CONTEXT.md— § CI and preview environments, § Environments - Composite action:
action.yml - Example workflow:
examples/github-actions/pr-preview.yml