Skip to content

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

  1. ✅ Verify Supabase CLI is installed and authenticated
  2. ✅ Obtain project reference ID from Supabase dashboard
  3. ✅ Test migrations locally (supabase db reset)
  4. ✅ Test edge function locally (supabase functions serve)
  5. ✅ Review and commit all changes

Phase 2: Database Deployment

  1. Link local project to remote: supabase link --project-ref <ref>
  2. Review pending migrations: supabase migration list
  3. Deploy migrations: supabase db push
  4. Verify migrations: supabase migration list
  5. Verify Postgres functions: Connect via psql and check \df

Phase 3: Edge Function Deployment

  1. Deploy function: supabase functions deploy browse
  2. Verify deployment: supabase functions list
  3. Test function endpoint: curl https://<ref>.supabase.co/functions/v1/browse/health

Phase 4: Configuration

  1. Set environment secrets (if needed): supabase secrets set KEY=value
  2. Verify secrets: supabase secrets list

Phase 5: Verification

  1. Test database functions via psql
  2. Test edge function endpoints
  3. Check function logs: supabase functions logs browse
  4. Verify in Supabase dashboard

Deployment Order

Critical: Database migrations MUST be deployed before edge functions if the edge function depends on new database schema.

  1. First: Deploy database migrations

    supabase db push
    

  2. Second: Deploy edge functions

    supabase functions deploy browse
    

  3. Third: Configure secrets (if needed)

    supabase secrets set KEY=value
    

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 URL
  • SUPABASE_ANON_KEY - Anonymous/public key
  • SUPABASE_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

  1. Secrets Management: Never commit secrets to version control
  2. RLS Policies: Ensure Row Level Security is properly configured
  3. Function Permissions: Review function access controls
  4. Database Access: Use connection pooling for production
  5. 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

  1. Test changes locally
  2. Create migration (if database changes)
  3. Update edge function code
  4. Deploy database migrations
  5. Deploy edge function
  6. Verify deployment
  7. 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