Skip to content

UF2: the D1 database from Terraform, the schema through db-migrate - #3

Merged
ruehowl merged 1 commit into
mainfrom
uf/2-the-database
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
uf/2-the-database

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

The monitor state's database, provisioned and migrated by Orun before the Worker that binds it deploys.

  • infra/terraform/cloudflare-d1 (turso-starter's root): one D1 database per deployed environment, its id and name lease-published as WIRING_CLOUDFLARE_D1. terraform validate passes.
  • packages/db: the control migration and 010_monitor_state (upstream's init.sql, table monitor_state), with turso-starter's runner over D1's REST API; infra/db-migrate runs it after the D1 apply.
  • apps/web now waits on both (enforced on main, advisory on PRs): cloudflare-d1 → db-migrate → web per environment — confirmed with a local orun plan for a push to main. init.sql gives way to db:migrate:local.
  • tests/db (14): the migrations into real SQLite, with the checker's own upsert/read, idempotent re-apply, the lock and the checksum guard. tests/web (24) checks its SQLite stand-in creates the same table.

Verified locally: install, typecheck, lint, test; db:migrate:local creates monitor_state in wrangler's local D1.


Generated by Claude Code

The monitor state's database, provisioned and migrated by Orun before the
Worker that binds it deploys:

- infra/terraform/cloudflare-d1 (turso-starter's root): one D1 database
  per deployed environment, named for the product, its id and name
  lease-published as the WIRING_CLOUDFLARE_D1 document the Worker's config
  renders from; `terraform validate` passes.
- packages/db: the control migration and 010_monitor_state — upstream's
  init.sql under the table name monitor_state — with turso-starter's
  runner over D1's REST API; infra/db-migrate runs it, after the D1 apply
  (enforced on main, advisory on a pull request).
- apps/web waits on both: one convergence runs cloudflare-d1 → db-migrate
  → web per environment. init.sql and `db:init:local` give way to
  `db:migrate:local`, which applies the same migrations to wrangler's
  local D1.
- tests/db: the migrations through the runner into real SQLite — the
  checker's own upsert and read on the schema, a second apply applying
  nothing, the lock, the checksum guard; tests/web holds the table its
  SQLite stand-in creates to the migration's.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
@ruehowl
ruehowl merged commit 040d738 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