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:
supabase/001_tables.sql
supabase/002_storage.sql
Feature migrations (run in order):
supabase/migrations/20260125_notifications.sql
supabase/migrations/20260126_notifications_enhancements.sql
supabase/migrations/20260127_notifications_indexes.sql
supabase/migrations/20260128_partner_reports.sql
supabase/migrations/20260128_rename_partner_to_investor.sql
supabase/migrations/20260129_investor_investment_schema.sql
supabase/migrations/20260130_multi_vehicle_funding_rounds.sql
supabase/migrations/20260131_email_invitations.sql
supabase/migrations/20260205000000_add_vehicle_depreciation_fields.sql
supabase/migrations/20260205100000_add_depreciation_method.sql
supabase/migrations/20260207000001_add_expense_fields.sql
supabase/migrations/20260207000002_create_audit_log.sql
supabase/migrations/20260207000003_migrate_categories.sql
supabase/migrations/20260212_fleet_pages.sql
supabase/migrations/20260213_fleet_pages_enhanced.sql
supabase/migrations/20260214_fleet_pages_testimonials_faq.sql
supabase/migrations/20260215_fleet_pages_social.sql
supabase/migrations/20260219_discrepancy_resolutions.sql
supabase/migrations/20260221_toll_accounts.sql
supabase/migrations/20260222_add_timezone_setting.sql
supabase/migrations/20260222_toll_transaction_unique_key.sql
supabase/migrations/20260223_toll_sync_scheduling.sql
supabase/migrations/20260307_investor_expense_treatment.sql
supabase/migrations/20260308_investor_agreements_align_columns.sql

Option B: Supabase CLI

npx supabase login
npx supabase db push --project-ref your-project-ref
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.