Repository navigation
SL2: the Supabase project from Terraform, the schema through db-migrate - #3
Merged
Merged
Conversation
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
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.
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 publishesWIRING_SUPABASE(the URL and publishable key),SUPABASE_PROJECT_REF,SUPABASE_DB_PASSWORDandSUPABASE_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:000_control;20240214102356_init.sql,20240214114147_auth-hook.sqlandseed.sql, copied byte for byte as010_init,020_auth_hookand030_seed, with their checksums inmanifest.ts. The seed is kept as a migration because the app sends every signed-in user to/channels/1.supabase/config.toml. Hereauth-config.tsholds the two keys. After the migrations, the runnerPATCHes them into/v1/projects/{ref}/config/authand 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. Anapplyre-asserts the hook every time. Aplantouches no Auth.infra/db-migrate:dependsOn: supabaseper environment, enforced on main and advisory on a pull request. Its four secrets are fail-closedsecretEnv.apps/web/component.yaml:supabaseanddb-migrate(enforced on main, advisory on a PR);WIRING_SUPABASE_<ENV>asoptionalSecretEnv;tests/db(18 tests, PGlite with Supabase's roles,authschema and publication stood in) covers:anonandauthenticated);anon, and member, moderator and admin permissions;replica identity full, upstream's checksums, and the Auth config the runner writes.Checked
orun validatepasses, and the lockfile is consistent with the workspace.pnpm testis green (db 18, web 18).Generated by Claude Code