Supabase Setup
HostMetrics uses Supabase for PostgreSQL database, authentication, and file storage.
1. Create a Supabase Project
- Go to supabase.com/dashboard
- Click “New Project”
- Choose your organization
- Set a project name (e.g., “hostmetrics-dev”)
- Set a strong database password (save it — you’ll need it for direct DB access)
- Select a region close to you
- Click “Create new project”
2. Get Your API Keys
After the project is created:
- Go to Settings > API
- Copy:
- Project URL →
NEXT_PUBLIC_SUPABASE_URL
- anon/public key →
NEXT_PUBLIC_SUPABASE_ANON_KEY
- service_role key →
SUPABASE_SERVICE_ROLE_KEY (for admin operations only)
3. Run Database Migrations
Option A: Supabase Dashboard (Recommended for first setup)
- Go to SQL Editor in your Supabase Dashboard
- 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.
Storage buckets are created by 002_storage.sql. Verify they exist:
- Go to Storage in Supabase Dashboard
- Confirm these buckets exist:
vehicle-photos — Vehicle images (public)
documents — Fleet documents (private)
If they don’t exist, re-run 002_storage.sql.
- Go to Authentication > Settings
- Email Auth: Enable (default)
- Confirm email: Disable for local development (or keep enabled for production)
- 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.