Database Management (Supabase)
1. Core Workflow
- •Environment: We use Supabase (PostgreSQL + Auth).
- •Local Config:
supabase/config.tomlmanages local settings. - •Env Vars: Ensure
.env.localis populated with valid Supabase credentials.
2. Key Commands
- •Push Migrations:
npm run db:push- •This pushes schema changes to the remote Supabase instance.
- •It also pushes the local configuration.
- •Link Database:
npm run db:link- •Links the local development environment to the remote Supabase project.
- •Generate Types:
npm run db:types- •Generates TypeScript definitions from the database schema. Run this after every schema change.
- •Deploy:
npm run deploy:supabase- •Deploys migrations and config (often used in CI/CD).
3. Schema Management
- •Migrations: SQL migrations are located in
libs/db/src(orsupabase/migrationsdepending on the exact setup - checksupabase/config.tomlworkdir). - •Validation: Always verify schema changes locally before pushing to production.
4. Troubleshooting
- •CSP/Connection Issues: If the build fails to connect to Supabase, check the Content Security Policy (CSP) headers in
next.config.jsormiddleware.ts. - •Url Sync: Ensure
NEXT_PUBLIC_URLmatches yoursite_urlin Supabase config to prevent redirect issues with auth.