Supabase Deployment Plan¶
Overview¶
This document outlines the deployment plan for deploying edge functions and Postgres functions to Supabase Cloud.
Deployment Components¶
1. Database Migrations (Postgres Functions)¶
Location: supabase/migrations/*.sql
What Gets Deployed:
- Database schema (tables, indexes, constraints)
- Postgres stored functions:
- get_current_snapshot_id() - Returns current active snapshot ID
- set_current_snapshot(UUID) - Sets and publishes a snapshot
- archive_snapshot(UUID) - Archives a published snapshot
- sparks_search_trigger() - Updates full-text search vector for sparks
- update_updated_at_column() - Auto-updates updated_at timestamps
- Database triggers
- Row Level Security (RLS) policies
- Enums and custom types
Deployment Method: supabase db push
Order: Migrations are applied in chronological order based on filename timestamps.
2. Edge Functions¶
Location: supabase/functions/browse/
What Gets Deployed:
- Main API application (index.ts)
- Deno runtime configuration (deno.json)
- All API routes and handlers
- Middleware and utilities
Deployment Method: supabase functions deploy browse
Runtime: Deno Deploy (serverless)
Deployment Workflow¶
Phase 1: Preparation¶
- ✅ Verify Supabase CLI is installed and authenticated
- ✅ Obtain project reference ID from Supabase dashboard
- ✅ Test migrations locally (
supabase db reset) - ✅ Test edge function locally (
supabase functions serve) - ✅ Review and commit all changes
Phase 2: Database Deployment¶
- Link local project to remote:
supabase link --project-ref <ref> - Review pending migrations:
supabase migration list - Deploy migrations:
supabase db push - Verify migrations:
supabase migration list - Verify Postgres functions: Connect via
psqland check\df
Phase 3: Edge Function Deployment¶
- Deploy function:
supabase functions deploy browse - Verify deployment:
supabase functions list - Test function endpoint:
curl https://<ref>.supabase.co/functions/v1/browse/health
Phase 4: Configuration¶
- Set environment secrets (if needed):
supabase secrets set KEY=value - Verify secrets:
supabase secrets list
Phase 5: Verification¶
- Test database functions via
psql - Test edge function endpoints
- Check function logs:
supabase functions logs browse - Verify in Supabase dashboard
Deployment Order¶
Critical: Database migrations MUST be deployed before edge functions if the edge function depends on new database schema.
-
First: Deploy database migrations
-
Second: Deploy edge functions
-
Third: Configure secrets (if needed)
Rollback Strategy¶
Database Rollback¶
- Create new migration to reverse changes
- Or manually execute SQL to drop/modify objects
- CAUTION: May cause data loss
Edge Function Rollback¶
- Redeploy previous version from version control
- Or fix and redeploy current version
Environment Variables¶
Automatic (Provided by Supabase)¶
SUPABASE_URL- Project API URLSUPABASE_ANON_KEY- Anonymous/public keySUPABASE_SERVICE_ROLE_KEY- Service role key (admin)
Custom (If Required)¶
- Set via:
supabase secrets set KEY=value - Accessible in edge functions via
Deno.env.get("KEY")
Post-Deployment Verification¶
Database Verification¶
- All migrations show "Applied" status
- Postgres functions exist and are callable
- Tables and indexes created correctly
- RLS policies active
Edge Function Verification¶
- Function shows "Active" status
- Health endpoint responds:
/health - API endpoints respond correctly
- Logs show no errors
- Authentication works (if required)
Monitoring¶
Logs¶
- Edge function logs:
supabase functions logs browse - Database logs: Available in Supabase dashboard
Metrics¶
- Function invocations: Supabase dashboard > Edge Functions
- Database performance: Supabase dashboard > Database > Performance
Security Considerations¶
- Secrets Management: Never commit secrets to version control
- RLS Policies: Ensure Row Level Security is properly configured
- Function Permissions: Review function access controls
- Database Access: Use connection pooling for production
- API Keys: Rotate keys regularly
Maintenance¶
Regular Tasks¶
- Monitor function logs for errors
- Review database performance metrics
- Update dependencies regularly
- Test migrations in staging before production
Update Process¶
- Test changes locally
- Create migration (if database changes)
- Update edge function code
- Deploy database migrations
- Deploy edge function
- Verify deployment
- Monitor for issues
Documentation¶
- Deployment Guide:
docs/DEPLOYMENT_GUIDE.md- Step-by-step CLI instructions - This Plan:
docs/DEPLOYMENT_PLAN.md- High-level deployment strategy - Database Setup:
docs/DATABASE_SETUP.md- Local database setup - Troubleshooting:
docs/TROUBLESHOOTING.md- Common issues and solutions
Success Criteria¶
✅ All migrations applied successfully
✅ All Postgres functions created and callable
✅ Edge function deployed and accessible
✅ Health endpoint returns 200 OK
✅ API endpoints respond correctly
✅ No errors in function logs
✅ Environment variables configured
✅ Dashboard shows all components active
Last Updated: 2025-01-02
Status: Ready for Deployment