Skip to content

SL2: the Supabase project from Terraform, the schema through db-migrate - #3

Merged
ruehowl merged 1 commit into
mainfrom
sl2-supabase-and-schema
Oct 29, 2026
Merged

ruehowl merged 1 commit into
mainfrom
sl2-supabase-and-schema

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

What this lands

The chat's backend (task SL-3).

  • infra/terraform/supabase: supabase-starter's root, named for this repository. It creates one project per environment and points the project's Auth Site URL and redirect allow-list at the Worker, with email confirmation off. It publishes WIRING_SUPABASE (the URL and publishable key), SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD and SUPABASE_DB_URL. It does not publish a service-role key, because nothing in the product runs with one.
  • packages/db (@saas/db, the name the db-migrate composition builds) contains:
    • the runner and 000_control;
    • upstream's 20240214102356_init.sql, 20240214114147_auth-hook.sql and seed.sql, copied byte for byte as 010_init, 020_auth_hook and 030_seed, with their checksums in manifest.ts. The seed is kept as a migration because the app sends every signed-in user to /channels/1.
  • The access-token hook: upstream switches it on in supabase/config.toml. Here auth-config.ts holds the two keys. After the migrations, the runner PATCHes them into /v1/projects/{ref}/config/auth and reads them back. This is done here rather than in Terraform: the supabase root applies first, so it would point Auth at a function that does not exist yet and break every sign-in until the migrations ran. An apply re-asserts the hook every time. A plan touches no Auth.
  • infra/db-migrate: dependsOn: supabase per environment, enforced on main and advisory on a pull request. Its four secrets are fail-closed secretEnv.
  • apps/web/component.yaml:
    • waits on supabase and db-migrate (enforced on main, advisory on a PR);
    • reads WIRING_SUPABASE_<ENV> as optionalSecretEnv;
    • re-renders its wrangler config from that document on stage and prod before the build.
  • tests/db (18 tests, PGlite with Supabase's roles, auth schema and publication stood in) covers:
    • the five tables under RLS, the roles trigger and the seed;
    • the hook's claims for each role, and its grants (denied to anon and authenticated);
    • nothing readable by anon, and member, moderator and admin permissions;
    • the Realtime publication with replica identity full, upstream's checksums, and the Auth config the runner writes.

Checked

  • orun validate passes, and the lockfile is consistent with the workspace.
  • The generated component docs match every manifest.
  • On the full tree: pnpm test is green (db 18, web 18).

Generated by Claude Code

infra/terraform/supabase (supabase-starter's root, named for this
repository) creates a Supabase project per environment, points its Auth
at the Worker with email confirmation off, and publishes WIRING_SUPABASE
(the URL and publishable key) and the three database credentials — no
service-role key. packages/db (@saas/db) carries upstream's two
migrations and its seed byte for byte as 010_init, 020_auth_hook and
030_seed, applied by db-migrate over the Management API's query endpoint,
each checked against its manifest checksum. Then the runner switches on
the custom access-token hook upstream's config.toml asks for — a PATCH of
the project's Auth config, read back — after the migrations that create
its function, so Auth never points at one that does not exist yet. The
app now waits on supabase and db-migrate, enforced on main and advisory on
a pull request, and reads its wiring per environment. tests/db proves the
schema on PGlite: the roles trigger, the hook's claims and grants, every
policy by role, the Realtime publication and its replica identity.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
@ruehowl
ruehowl merged commit bebd944 into main Oct 29, 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