Skip to main content

Supabase Setup

HostMetrics uses Supabase for PostgreSQL database, authentication, and file storage.

1. Create a Supabase Project

  1. Go to supabase.com/dashboard
  2. Click “New Project”
  3. Choose your organization
  4. Set a project name (e.g., “hostmetrics-dev”)
  5. Set a strong database password (save it — you’ll need it for direct DB access)
  6. Select a region close to you
  7. Click “Create new project”

2. Get Your API Keys

After the project is created:
  1. Go to Settings > API
  2. Copy:
    • Project URLNEXT_PUBLIC_SUPABASE_URL
    • anon/public keyNEXT_PUBLIC_SUPABASE_ANON_KEY
    • service_role keySUPABASE_SERVICE_ROLE_KEY (for admin operations only)

3. Run Database Migrations

  1. Go to SQL Editor in your Supabase Dashboard
  2. Run each migration file from supabase/ in order:
Initial schema:
Feature migrations (run in order):

Option B: Supabase CLI

The CLI approach may have issues with duplicate timestamp prefixes in migration filenames. If you encounter errors, use the Dashboard SQL Editor instead.

4. Configure Storage Buckets

Storage buckets are created by 002_storage.sql. Verify they exist:
  1. Go to Storage in Supabase Dashboard
  2. Confirm these buckets exist:
    • vehicle-photos — Vehicle images (public)
    • documents — Fleet documents (private)
If they don’t exist, re-run 002_storage.sql.

5. Configure Auth Settings

  1. Go to Authentication > Settings
  2. Email Auth: Enable (default)
  3. Confirm email: Disable for local development (or keep enabled for production)
  4. Redirect URLs: Add http://localhost:3000/** for local dev

Row Level Security (RLS)

All tables have RLS enabled. Every query filters by user_id to ensure multi-tenant data isolation. The getCurrentUserId() helper in src/lib/db/_client.ts extracts the authenticated user’s ID from the Supabase session.