Skip to content

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

Merged
ruehowl merged 1 commit into
mainfrom
sv/2-supabase-and-schema
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
sv/2-supabase-and-schema

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

This adds each environment's Supabase project (Terraform), the schema (upstream's two migrations, applied by db-migrate) and the tests for both.

  • infra/terraform/supabase: supabase-starter's root, renamed.
    • One project per environment, waited on until it is healthy.
    • Its Auth points at the app's Worker: the Site URL, the redirect allow-list, and email confirmation off until the project has SMTP of its own.
    • It publishes, as Orun secrets:
      • the project ref and database credentials, for db-migrate;
      • WIRING_SUPABASE (the URL and anon key), which the app's build renders;
      • the service-role key, as SUPABASE_SERVICE_ROLE_KEY (new here).
    • Upstream's server needs the service-role key for the contact form, Stripe customers and account deletion. Only that environment's deploy lane reads it, and it reaches the Worker as a secret.
    • terraform validate passes.
  • packages/db (@saas/db, the name the db-migrate composition builds): saas-starter's runner over the Management API. It carries upstream's two supabase/migrations files, byte for byte, as 010_initial and 020_add_unsubscribed_to_profiles.
  • infra/db-migrate: applies them per environment, waiting on main for the project's apply. apps/web now waits for both, so a merge plans supabase → db-migrate → web, which a local orun plan confirms.
  • tests/db: the manifest and its checksums, checked against upstream's files. The runner runs against PGlite with Supabase's roles, auth.users, auth.uid() and Storage stood in. The 10 tests cover:
    • every migration applied once, and a second apply applying nothing;
    • the three tables under row-level security;
    • the profile trigger;
    • own-row access only;
    • no API role seeing the two server-only tables;
    • the avatars bucket and its policies.

Locally: install, typecheck, lint, test and build are all green.


Generated by Claude Code

infra/terraform/supabase is supabase-starter's root, renamed: one project per
environment, waited on until it is healthy, its Auth pointed at the app's
Worker (Site URL, redirect allow-list, email confirmation off until the
project has SMTP of its own), and published to orun secrets after the apply:
the project ref and database credentials (db-migrate's), WIRING_SUPABASE (the
URL and anon key the app's build renders) and — new here, because upstream's
server uses it for the contact form, Stripe customers and account deletion —
the service-role key as SUPABASE_SERVICE_ROLE_KEY, which only that
environment's deploy lane reads and hands the Worker as a secret.
`terraform validate` passes.

packages/db (@saas/db, the name the db-migrate composition builds) carries
saas-starter's runner over the Management API and upstream's two
supabase/migrations files, byte for byte, as 010_initial and
020_add_unsubscribed_to_profiles. infra/db-migrate applies them per
environment, waiting (enforced on main) for the project's apply; apps/web
now waits for both, so a merge plans supabase → db-migrate → web.

tests/db runs the manifest, the checksums against upstream's files and the
runner against PGlite with Supabase's roles, auth.users, auth.uid() and
Storage stood in: every migration applied once and a second apply applying
nothing; the three tables under row-level security; the trigger giving each
new user a profile from their sign-up metadata; a user reading and writing
only their own profile; the anon key and every API role seeing nothing of
the two server-only tables; the avatars bucket and its policies. 10 tests.

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