Skip to content

BA2: D1, KV and R2 from Terraform, the schema through db-migrate - #3

Merged
ruehowl merged 1 commit into
mainfrom
ba/2-the-data-plane
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
ba/2-the-data-plane

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

The example has its owner create the three bindings by hand. This PR makes them Terraform roots that Orun applies per environment:

  • The roots: infra/terraform/cloudflare-d1 (turso-starter's), cloudflare-kv (kv-redis-starter's) and cloudflare-r2 (blob-starter's), as ai-emoji-generator combined them. Each lease-publishes the wiring document the Worker's config renders from (WIRING_CLOUDFLARE_{D1,KV,R2}).
  • The migrations lane: infra/db-migrate runs packages/db's runner over D1's REST API after the database's apply. That creates better-auth's tables and the generated auth secret.
  • The web component: apps/web now waits on all four on a merge to main (enforced; advisory on a pull request). Stage and prod render from their wiring documents; dev renders from the fixture.
  • A fix for BA1: this restores the packages/db, tests/db and tests/web component manifests in full. BA1 landed them cut short by a faulty edit of mine. Nothing noticed, because CI plans nothing while the workspace is the placeholder.

Checks run locally

  • terraform validate passes on all three roots.
  • orun plan --trigger github-push-main --env stage, run against a stand-in workspace, gives the expected order:
    • cloudflare-d1, cloudflare-kv and cloudflare-r2 first;
    • then db-migrate (after d1);
    • then web (after all four).
  • pnpm test: tests/web 22, tests/db 14. The committed wrangler.jsonc is unchanged by a re-render.

Generated by Claude Code

The three bindings the example asked its owner to create by hand, as
Terraform roots Orun applies per environment: turso-starter's cloudflare-d1,
kv-redis-starter's cloudflare-kv and blob-starter's cloudflare-r2 (as
ai-emoji-generator combined them), each lease-publishing the wiring document
the Worker's config renders from. infra/db-migrate runs packages/db's
runner over D1's REST API after the database's apply — better-auth's tables
and the generated auth secret — so the auth app never meets a database
without its schema.

apps/web now waits on all four on a merge to main (enforced; advisory on a
pull request) and renders stage and prod from their wiring documents, dev
from the fixture; the product's own plan orders the roots, then the
migrations, then the Worker. Every root passes terraform validate.

This also restores the packages/db, tests/db and tests/web component
manifests in full: BA1 landed them cut short by a faulty edit, unnoticed
because CI plans nothing while the workspace is the placeholder.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
@ruehowl
ruehowl merged commit 20fc15a into main Oct 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants