Prerequisites

  • Node.js 16+ installed
  • Docker installed (for local development)
  • Git installed
  • A Supabase account (for cloud deployment)

Local Development Setup

1. Install Supabase CLI

npm install -g supabase

2. Initialize Supabase in Your Project

cd your-project
supabase init
This creates a supabase directory with the following structure:
supabase/
├── config.toml
├── seed.sql
└── migrations/

3. Start Local Supabase Services

supabase start
This command:
  • Starts a local PostgreSQL database
  • Starts the Supabase API
  • Starts the Supabase Auth service
  • Starts the Supabase Storage service
  • Starts the Supabase Edge Functions service

4. Access Local Services

After starting the services, you’ll see URLs for:
  • API: http://localhost:54321
  • Studio: http://localhost:54323
  • Database: postgresql://postgres:postgres@localhost:54322/postgres

5. Configure Environment Variables

Create a .env file in your project root:
# Local Development
DATABASE_URL="postgresql://postgres:postgres@localhost:54322/postgres"
DIRECT_URL="postgresql://postgres:postgres@localhost:54322/postgres"
SUPABASE_URL="http://localhost:54321"
SUPABASE_ANON_KEY="your-anon-key"
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"

Cloud Deployment

1. Create a Supabase Project

  1. Go to supabase.com
  2. Sign in or create an account
  3. Click “New Project”
  4. Fill in the project details:
    • Name
    • Database password
    • Region
    • Pricing plan

2. Get Project Credentials

After project creation, you’ll get:
  • Project URL
  • API Keys (anon and service_role)
  • Database connection strings

3. Update Environment Variables

Update your .env file with production credentials:
# Production
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
DIRECT_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"
SUPABASE_URL="https://[YOUR-PROJECT-REF].supabase.co"
SUPABASE_ANON_KEY="your-anon-key"
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"
supabase link --project-ref your-project-ref

Database Management

Using Supabase Studio

  1. Access Studio:
    • Local: http://localhost:54323
    • Cloud: https://app.supabase.com
  2. Features available:
    • Table editor
    • SQL editor
    • Database backups
    • User management
    • API documentation

Database Migrations

  1. Create a migration:
supabase migration new your_migration_name
  1. Apply migrations:
supabase db push
  1. Reset database:
supabase db reset

Security Best Practices

  1. API Keys
    • Never commit API keys to version control
    • Use environment variables
    • Rotate keys regularly
  2. Database Security
    • Use strong passwords
    • Enable SSL connections
    • Set up IP allow lists
  3. Row Level Security (RLS)
    • Enable RLS on tables
    • Define appropriate policies
    • Test security policies

Monitoring and Maintenance

1. Database Monitoring

  • Use Supabase Dashboard for:
    • Query performance
    • Database size
    • Connection pool
    • Error rates

2. Regular Maintenance

  • Monitor database size
  • Check for unused indexes
  • Review and optimize queries
  • Regular backups

Troubleshooting

Common Issues

  1. Connection Problems
    # Check Supabase status
    supabase status
    
    # Restart services
    supabase stop
    supabase start
    
  2. Migration Issues
    # Reset database
    supabase db reset
    
    # Check migration status
    supabase migration list
    
  3. Performance Issues
    • Check query performance in Studio
    • Review database indexes
    • Monitor connection pool

Additional Resources