Context
Local development runs Postgres in Docker (ADR-0006). A deployed environment needs a managed Postgres with vector and pg_trgm, backups and a dashboard the whole team can reach, at no cost for a capstone. Supabase project smart-learning-ai (ref lqbnldwxodvhmevfunkw, region ap-southeast-2) provides that.
Decision
- Supabase is only a Postgres host. The app does not use Supabase Auth, Storage, Realtime or the Data API. NestJS stays the only way into the data (ADR-0002, ADR-0007).
- Prisma owns the schema. Migrations reach Supabase through
prisma migrate deploy, never through the Supabase dashboard or the MCPapply_migrationtool. Otherwise the two migration histories drift apart. - Extensions are created by hand, in the
extensionsschema, matchinginfra/db/init/001-extensions.sql:vectorandpg_trgm. - The Data API is closed.
anonandauthenticatedhave no privileges onpublic, including default privileges for tables created later. RLS is enabled with no policies (deny-all). The app connects aspostgres, which owns the tables and is not affected. - The connection string lives in
.env.localasSTAGING_DATABASE_URL. It is never committed.
Alternatives considered
- Postgres in the compose stack on a VPS. Backups and upgrades become our job.
- Neon. Comparable, but the team already works in the Supabase dashboard.
Consequences
- To migrate staging:
DATABASE_URL="$STAGING_DATABASE_URL" pnpm --filter @smartlearn/database exec prisma migrate deploy. STAGING_DATABASE_URLis the Session pooler string (postgres.<ref>@…pooler.supabase.com:5432), because the direct hostdb.<ref>.supabase.cois IPv6-only and many CI runners lack IPv6. Never use the Transaction pooler (port 6543) for migrations.- Every migration that adds a table must also
ENABLE ROW LEVEL SECURITYon it, or the Supabase security advisor reports it. The revoked grants already keep it unreachable. - The advisor's
rls_enabled_no_policynotice is expected and stays.