Repository navigation
PD4: postgres-drizzle-starter becomes an Orun baseline - #5
Merged
Merged
Conversation
The repository is an Orun baseline on the Lumen (Cloudflare + Supabase) conventions, built the way cirrus-baseline v22 builds a product: ONE landing. 01-product places every module, brands it, links the repository, reconciles five brokered keys and lands it as one pull request; the convergence after that merge applies supabase -> cloudflare-hyperdrive -> db-migrate -> web per environment, every edge enforced on a push to main and advisory on a pull request. 02-docs is hook-only. The table moves from the page to db-migrate. Upstream created `profiles` from its first request: the table component caught `relation "profiles" does not exist` and ran seed.ts, whose CREATE TABLE IF NOT EXISTS is idempotent but not safe under concurrent first requests (2 of 160 racing sessions failed on pg_type_typname_nsp_index / pg_class_relname_nsp_index, Postgres 16). So: - packages/db (Lumen's runner, named @saas/db because stack-tectonic's db-migrate composition builds that filter): 000_control, 010_profiles (drizzle-kit's output for lib/drizzle.ts, IF NOT EXISTS), and 020_row_level_security (RLS, no policy, with the reference's lock-out guard); drizzle-kit twins in apps/web/lib/migrations for local use; infra/db-migrate after supabase and cloudflare-hyperdrive. - The page seeds only rows, on an empty table (INSERT ... ON CONFLICT (email) DO NOTHING, safe to race); a missing table renders a notice. - /api/health: 200 only when the database answers through the HYPERDRIVE binding and profiles exists with RLS. The smoke reads it and the page. - tests/db (PGlite) fails on any table in public without RLS, drives the guard both ways, and holds the twins to the same statements. The baseline: blueprint.yaml (requires [github, cloudflare, supabase], five secrets previewed, two Supabase projects as an owner prerequisite), repo-blueprint.yaml, .baseline/, the rename engine with the SITE_NAME seam, tooling/bootstrap, hooks/render-deployment-docs.sh, ai/context, docs/phases, BOOTSTRAP.md, testing/ and the baseline.yml / tag.yml lanes. Also: stack-tectonic 0.19.0, checks.yml on pull requests only, ci.yml's linked gate, wrangler.jsonc committed as the fixture render, the supabase root reduced to Lumen's three outputs with lock files on both roots, and the build's site origin written out (it read a subdomain the build never had). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
The Hyperdrive config caches read queries for up to a minute (Lumen's root: caching on; 60 s max_age, 15 s stale-while-revalidate) and does not invalidate them on a write. Upstream's first select failed, so nothing empty was ever cached; seeding on an EMPTY table changes that: the first select succeeds with no rows and is cached, and the same select after the seed would be answered from it, so a fresh environment's first visitors would see "Fetched 0 users" for up to a minute. The read-back after a seed now adds `where now() is not null`. Cloudflare documents that a query calling a STABLE or VOLATILE function is never cached, so it reaches the database. Ordinary page views stay cacheable. /api/health already calls to_regclass (STABLE) and is never cached. tests/web holds the read-back's shape. wrangler dev's local binding has no cache, so the e2e cannot observe this; its wording now says so. Documented in operations.md and risk PD-I. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
ruehowl
marked this pull request as ready for review
October 15, 2026 20:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PD4 (task PD-5): this repository becomes an Orun baseline on the Lumen (Cloudflare + Supabase) conventions, built the way cirrus-baseline v22 builds a product — one landing. The reference is sourceplane/saas-starter#6.
How the table got created, and what changed
Upstream (and PD0–PD3) created
profileson the first request:components/table.tsxcaughtrelation "profiles" does not existand ranlib/seed.ts—CREATE TABLE IF NOT EXISTS, then threeINSERT … ON CONFLICT (email) DO NOTHING. No migration, no seed script, no drizzle push.That DDL is idempotent but not safe under concurrent first requests:
IF NOT EXISTSis not checked under a lock, so two sessions can both create the table and one fails on Postgres's catalog index. Measured on Postgres 16 with upstream's exact DDL: 2 of 160 racing sessions failed (pg_type_typname_nsp_index,pg_class_relname_nsp_index) — each a 500 for that visitor. So the schema moved to db-migrate, and the chain is supabase → cloudflare-hyperdrive → db-migrate → web, enforced on a push to main and advisory on PRs.packages/dbis Lumen's runner, named@saas/db(stack-tectonic 0.19.0's db-migrate composition builds--filter=@saas/db). Migrations:000_control,010_profiles(drizzle-kit's output forlib/drizzle.ts, withIF NOT EXISTS),020_row_level_security. The drizzle-kit twins are inapps/web/lib/migrations(pnpm db:migratelocally), andtests/dbchecks the two copies have the same statements.ON CONFLICT (email) DO NOTHING, which is safe to race). A missing table renders an "apply the migrations" notice instead of creating it.where now() is not null: Cloudflare documents that queries calling STABLE or VOLATILE functions are never cached./api/healthis never cached either (to_regclassis STABLE). This is risk PD-I; it can't be observed offline, becausewrangler dev's local binding has no cache..enableRLS()is declared in the schema.tests/db(PGlite) fails if anypublictable lacks RLS, and drives the guard both ways./api/health: 200 only when the database answers through theHYPERDRIVEbinding andprofilesexists with RLS. The smoke reads it, plusRecent Userson/.The baseline
blueprint.yaml(requires[github, cloudflare, supabase]; previews the five brokered keys: workers-deploy, hyperdrive-edit, account-id, management-access, org-id) andrepo-blueprint.yaml. Phase01-productplaces every module and runs the reference's hook chain. Phase02-docsis hook-only.SUPABASE_PROJECT_REF,SUPABASE_DB_PASSWORD,SUPABASE_DB_URLandWIRING_CLOUDFLARE_HYPERDRIVEon stage and prod; probes/and/api/healthon both..baseline/, the rename engine (SITE_NAMEseam inapps/web/lib/site.ts),tooling/bootstrap,hooks/render-deployment-docs.sh(its Stripe section became a Database section),ai/context,docs/phases,BOOTSTRAP.md,testing/, and thebaseline.yml/tag.ymllanes.testing/lib/*, the manifest/coverage/retouch/bootstrap-defer tests,tooling/bootstrap/*,ci.yml,tag.yml, the Terraform roots and their lock files.checks.ymlruns on PRs only.ci.ymluses thelinkedgate.wrangler.jsoncis committed as the fixture render.${WORKERS_DEV_SUBDOMAIN}, which the composition exports only to the smoke step, so every build would have had an empty subdomain.Verified
All of this ran locally on this branch (Node 22.22, pnpm 10.12.1, Postgres 16, terraform 1.15.3).
The repository's own checks — all green
pnpm install --frozen-lockfile,wire:fixture(leaves the committedwrangler.jsoncunchanged), typecheck, lint, build (/and/api/healthareƒ).test: 29 tests — 17 intests/web, 12 intests/db.pnpm --filter @saas/db run manifest:check.generate: "No schema changes" (the twins match the schema).testing/*.test.sh— all okmanifest,phases,coverage,rebrand(31 cases, including an acme name with'and&),retouch,bootstrap-defer.leak: 107 files placed; none of the factory paths ships or is named.placement:supabase → cloudflare-hyperdrive → db-migrate → web, enforced, on stage and prod.--resumeis a no-op.e2e: green under orun 2.79.0 and v2.78.4 (the lane pin). The final run was at v2.78.4, on the head commit.000/010/020, a second apply is a no-op, and the PR plan step verifies checksums.profilesexists before the app serves — empty, with RLS on, owned bypostgres.verify-app-structure,build-app(Turbopack, inside its own tree, re-rendered with the stage Hyperdrive id),verify-build-outputanddeploy-dry-run.wrangler devwith the Hyperdrive binding on the local Postgres:/serves under the product's name, with Open Graph on the stage origin and the upstream link kept./api/healthanswered, and so did 4 static assets and a 404.anonandauthenticatedsee 0 rows and cannot write; the app's role is neither superuser nor BYPASSRLS.orun and Terraform
orun new --status: v2.58.11, v2.78.4 and 2.79.0.orun validateandorun work check: clean.terraform fmt -check,init -backend=false(the committed lock files unchanged) andvalidate: green on both roots.Verified only offline
These all need a linked workspace with Cloudflare and Supabase connections; Terraform is verified to
validateonly.One flake while testing: one v2.78.4 e2e run failed
Migration Applywithfetch failedagainst the local Management API stand-in. Two 2.79.0 runs had passed that step, and the rerun passed. The e2e now checks that the stand-in is answering before the migrate lane and prints its log, instead of failing with a barefetch failed.🤖 Generated with Claude Code
https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk