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:
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.
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.