Skip to content

AT2: Supabase and Hyperdrive from Terraform, the schema through db-migrate - #3

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

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

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

This PR adds the data plane behind the CRM's Worker.

  • infra/terraform/supabase (supabase-starter's root) creates one Supabase project per environment.
    • Auth's Site URL and redirect allow-list point at the Worker, and sign-up signs the user straight in.
    • It publishes the database credentials and WIRING_SUPABASE (the URL and publishable key).
    • It also publishes SUPABASE_SERVICE_ROLE_KEY. Only the Worker's deploy reads it, and stores it as a Worker secret for the admin functions.
  • infra/terraform/cloudflare-hyperdrive puts a Hyperdrive config in front of each project's Postgres, with caching off.
  • packages/db (@saas/db) holds 33 checksummed migrations, applied through the Management API by infra/db-migrate before the Worker deploys:
    • Upstream's history: its 30 supabase/migrations, in order. This is what supabase db push applies. I compared it with upstream's declarative supabase/schemas on a Supabase-shaped Postgres 16. The two match except for one column's position and one grant the declarative files still give (get_user_id_by_email to anon and authenticated), which the history revokes. So the history is what ships.
    • Three marked edits: pgjwt is not created (it's unused, and absent on Postgres 17). http and pg_net are created where they are installed.
    • Upstream's seed, which its remote setup applies with --include-seed.
    • The port's outbox: cleanup_note_attachments() now queues the note's old and new record. The Worker's Cron Trigger (every ten minutes) drains the queue through the Storage API, using upstream's own getPathsToDelete. Upstream's trigger called the edge function through pg_net instead, and the database has no address for the Worker.
  • apps/web now deploys after supabase, cloudflare-hyperdrive and db-migrate, and renders its config from their wiring documents.
  • tests/db applies every migration with db-migrate's runner to a Supabase-shaped PGlite, twice; the second run applies nothing. It then checks:
    • the first sign-up becomes the administrator;
    • contacts through the Data API's roles;
    • auth.users emails are kept from those roles;
    • the bucket and its policies;
    • the seed;
    • the outbox, and that the queue is closed to the Data API roles.
  • tooling/catalog generates each component's docs from its manifests.

Checked locally:

  • terraform validate passes for both roots.
  • The 33 migrations apply as Supabase's non-superuser postgres on a real Postgres 16.
  • pnpm typecheck, lint, test and build are green: 437 web tests plus upstream's skip, and 16 DB tests.
  • orun plan gives 7 components × 3 envs → 14 jobs.

Generated by Claude Code

…grate

infra/terraform/supabase (supabase-starter's root) creates each
environment's Supabase project with Auth pointed at the Worker and sign-up
signing straight in, and publishes the database credentials, the wiring
document the build and the Worker read (URL and publishable key) and the
service-role key, which only the Worker's deploy reads, to store as a Worker
secret for the admin functions. infra/terraform/cloudflare-hyperdrive puts a
Hyperdrive config, caching off, in front of each project's Postgres.

packages/db (@saas/db) carries upstream's 30 supabase/migrations in their
order — the history supabase db push applies, which a comparison on a
Supabase-shaped Postgres showed to be the schema upstream's declarative files
describe, less one grant they still give — then its seed, then the port's
outbox: cleanup_note_attachments() queues a note's old and new record, and
the Worker's Cron Trigger drains the queue through the Storage API with
upstream's own getPathsToDelete, where upstream's trigger called the edge
function through pg_net. Three upstream files carry a marked edit (pgjwt,
absent on Postgres 17, is not created; http and pg_net are created where
installed). infra/db-migrate applies them through the Management API before
the Worker deploys.

tests/db applies every migration with db-migrate's runner to a
Supabase-shaped PGlite, twice, and checks sign-up, the Data API's roles, the
bucket and its policies, the seed and the outbox; tests/web covers the drain.
tooling/catalog generates each component's docs from its manifests.

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