Skip to content

Commit 0f5df79

Browse files
authored
chore(infra): simplify production database operations (#37)
## Summary - Use the production Supabase runtime roles for both local and deployed Workers. - Remove orphaned release, local database, compatibility, and dead API surfaces. - Align Vault and Worker-role migrations with managed Supabase behavior. - Restore the direct Cloudflare deploy plus explicit expand/contract migration path. ## Decisions - Runtime Workers keep distinct least-privilege database roles. - Administrative migration credentials remain isolated in `.env.migrate`. - Production contractions remain a separate guarded operation after the matching release is live. - Vercel Git deployment is re-enabled for the web app. ## Validation - `pnpm typecheck` - `pnpm lint` - `pnpm build` - `pnpm architecture:check` - `pnpm deadcode` - `pnpm dev:services --dry-run` - production pre-deploy migrations and target identity verification ## Rollout 1. Merge after `static-checks`. 2. Verify the production web revision. 3. Deploy the four Cloudflare services. 4. Verify service health. 5. Apply the guarded post-deploy contraction phase. 6. Verify production UI, console, network, and Worker logs.
1 parent ac39dd9 commit 0f5df79

37 files changed

Lines changed: 499 additions & 3735 deletions

.env.example

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
# Root .env.local is the only local credential file. Cloudflare and Vercel
2-
# receive production values directly in their dashboards; never copy this file there.
3-
4-
# Local Postgres. Generate four distinct URL-safe passwords and keep each Worker
5-
# password identical to the password in only its own connection URL.
6-
LOCAL_POSTGRES_PASSWORD=replace_with_64_hex_postgres_password
7-
LOCAL_APP_GATEWAY_PASSWORD=replace_with_64_hex_app_gateway_password
8-
LOCAL_APP_AGENT_PASSWORD=replace_with_64_hex_app_agent_password
9-
LOCAL_APP_WEBHOOKS_PASSWORD=replace_with_64_hex_app_webhooks_password
10-
LOCAL_DATABASE_PORT=54322
11-
CHEATCODE_LOCAL_DATABASE=true
12-
SUPABASE_MIGRATION_URL=postgresql://postgres:replace_with_64_hex_postgres_password@database:5432/postgres
13-
SUPABASE_MIGRATION_EXPECTED_HOST=database
14-
SUPABASE_MIGRATION_EXPECTED_DATABASE=postgres
15-
SUPABASE_MIGRATION_EXPECTED_ROLE=postgres
16-
LOCAL_GATEWAY_DATABASE_URL=postgresql://app_gateway:replace_with_64_hex_app_gateway_password@database:5432/postgres
17-
LOCAL_AGENT_DATABASE_URL=postgresql://app_agent:replace_with_64_hex_app_agent_password@database:5432/postgres
18-
LOCAL_WEBHOOKS_DATABASE_URL=postgresql://app_webhooks:replace_with_64_hex_app_webhooks_password@database:5432/postgres
1+
# Root .env.local is the only local application credential file. Local Workers
2+
# use the production Supabase database through its public session pooler and the
3+
# same three least-privilege roles as production Hyperdrive. Keep each password
4+
# identical to the password configured on only its matching production role.
5+
# Administrative migration credentials belong in .env.migrate, never here.
6+
SUPABASE_GATEWAY_DATABASE_URL=postgresql://app_gateway.snqtclnmhcaupqynjyux:replace_with_gateway_role_password@aws-0-ap-south-1.pooler.supabase.com:5432/postgres?sslmode=require&uselibpqcompat=true
7+
SUPABASE_AGENT_DATABASE_URL=postgresql://app_agent.snqtclnmhcaupqynjyux:replace_with_agent_role_password@aws-0-ap-south-1.pooler.supabase.com:5432/postgres?sslmode=require&uselibpqcompat=true
8+
SUPABASE_WEBHOOKS_DATABASE_URL=postgresql://app_webhooks.snqtclnmhcaupqynjyux:replace_with_webhooks_role_password@aws-0-ap-south-1.pooler.supabase.com:5432/postgres?sslmode=require&uselibpqcompat=true
199

2010
# Clerk development instance. These test keys are for this laptop only; every
2111
# Vercel environment uses the production Clerk instance.

.env.migrate.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copy to .env.migrate only on an authorized operator workstation. This file
2+
# targets the production Supabase database and is never loaded by the app,
3+
# Compose, Wrangler, Next.js, or any Worker.
4+
SUPABASE_MIGRATION_URL=postgresql://postgres:replace_with_production_admin_password@db.snqtclnmhcaupqynjyux.supabase.co:5432/postgres?sslmode=require
5+
SUPABASE_MIGRATION_EXPECTED_HOST=db.snqtclnmhcaupqynjyux.supabase.co
6+
SUPABASE_MIGRATION_EXPECTED_DATABASE=postgres
7+
SUPABASE_MIGRATION_EXPECTED_ROLE=postgres
8+
SUPABASE_MIGRATION_EXPECTED_SYSTEM_IDENTIFIER=replace_with_pg_control_system_identifier
9+
10+
# Optional one-time protected migration attestation envelope.
11+
CHEATCODE_MIGRATION_ATTESTATIONS=

.github/workflows/deploy-workers.yml

Lines changed: 0 additions & 229 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ qa-*.png
1515
.env
1616
.env.*
1717
!.env.example
18+
!.env.migrate.example
1819
apps/*/.dev.vars
1920
apps/*/wrangler.local-dev.generated.jsonc
2021
apps/*/wrangler.production.*.generated.json

AGENTS.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,18 @@ not write, run, or keep scripts to submit prompts, click UI, drive auth, wrap
117117
## Run locally
118118

119119
```bash
120-
pnpm dev # Compose: Postgres + migrations + Next + chained Workers
120+
pnpm dev # Compose: Next + chained Workers against production Supabase
121121
pnpm dev:down # Stop the local Compose stack
122122
```
123123

124124
Required local env vars in `.env.local` (template in `.env.example`):
125125

126126
```
127-
# Local Postgres + per-Worker roles (distinct URL-safe passwords)
128-
LOCAL_POSTGRES_PASSWORD=
129-
LOCAL_APP_GATEWAY_PASSWORD=
130-
LOCAL_APP_AGENT_PASSWORD=
131-
LOCAL_APP_WEBHOOKS_PASSWORD=
132-
SUPABASE_MIGRATION_URL=postgresql://postgres:<local-password>@database:5432/postgres
133-
LOCAL_GATEWAY_DATABASE_URL=postgresql://app_gateway:<gateway-password>@database:5432/postgres
134-
LOCAL_AGENT_DATABASE_URL=postgresql://app_agent:<agent-password>@database:5432/postgres
135-
LOCAL_WEBHOOKS_DATABASE_URL=postgresql://app_webhooks:<webhooks-password>@database:5432/postgres
127+
# Production Supabase session-pooler URLs for the three isolated Worker roles.
128+
# Administrative migration credentials never belong in .env.local.
129+
SUPABASE_GATEWAY_DATABASE_URL=
130+
SUPABASE_AGENT_DATABASE_URL=
131+
SUPABASE_WEBHOOKS_DATABASE_URL=
136132
137133
# Per-Worker signed tenant context (three distinct secrets, each at least 32 bytes)
138134
DATABASE_CONTEXT_SIGNING_SECRET_GATEWAY=
@@ -173,9 +169,11 @@ RELEASE_DATABASE_READINESS_SECRET=
173169
NEXT_PUBLIC_GATEWAY_URL=http://127.0.0.1:8787
174170
```
175171

176-
Never commit `.env.local`. It is the sole laptop credential file and accepts only
177-
Clerk test keys plus sandbox/local credentials. Vercel and Cloudflare receive
178-
production credentials directly through their protected production environments.
172+
Never commit `.env.local`. It is the sole laptop application credential file;
173+
its database URLs contain only the three least-privilege production runtime
174+
roles. Vercel and Cloudflare receive production credentials directly through
175+
their protected production environments. Administrative migration credentials
176+
live only in git-ignored `.env.migrate` on authorized operator workstations.
179177

180178
## Code conventions (CI-enforced)
181179

0 commit comments

Comments
 (0)