Prerequisites
- Supabase account (sign up free)
- Git access to Hiro CRM repository
- Basic familiarity with SQL (helpful but not required)
Create Supabase Project
Create a new project
- Go to Supabase Dashboard
- Click New Project
- Fill in project details:
- Name:
hiro-crm-production(or your preferred name) - Database Password: Generate a strong password (save this!)
- Region: Choose closest to your users (e.g.,
West EU (London)for Spain) - Pricing Plan: Free tier works for getting started
- Name:
- Click Create new project
Project creation takes 1-2 minutes. Supabase provisions a dedicated PostgreSQL database for you.
Get your connection details
Once created, navigate to Project Settings → API:Save these values for your environment variables:
- Project URL:
NEXT_PUBLIC_SUPABASE_URL - Anon/Public Key:
NEXT_PUBLIC_SUPABASE_ANON_KEY - Service Role Key:
SUPABASE_SERVICE_ROLE_KEY
Database Architecture
Hiro CRM uses a comprehensive database schema optimized for hospitality CRM:Core Tables
profiles- User accounts and rolesbrands- Restaurant brands (e.g., “La Tasca”, “El Patio”)locations- Physical restaurant locationscustomers- Customer profiles with full CRM datareservations- Reservation history and trackingcampaigns- Marketing campaigns (email/SMS)feedback_surveys- NPS and customer feedback
Feature Modules
- Loyalty:
loyalty_program_config,loyalty_tier_config,loyalty_transactions - Calendar:
calendar_events,calendar_notifications - Tickets:
tickets,ticket_comments,ticket_notifications - Automations:
automations,automation_logs - HR:
employees,employee_assignments - Library:
library_folders,library_files
System Tables
subscription_plans- Available pricing plansintegration_configs- POS and third-party integrationssettings- Application settings
The schema is designed for single-tenant use with optional multi-location support.
Running Migrations
Hiro CRM includes migration files in two locations:/supabase/migrations/- Root migrations (older, legacy schema)/frontend/supabase/migrations/- Frontend migrations (current, recommended)
Method 1: Supabase CLI (Recommended)
Method 2: SQL Editor (Manual)
If you prefer to run migrations manually:Run migrations in order
Copy and paste the contents of each migration file in order:
001_optimizations_v1.sql002_SEED_GRUPO_GASTRO_PORTAL.sql(optional - includes sample org)003_UPDATE_COVERMANAGER_SLUGS.sql- Continue through all numbered migrations…
010_HIRO_COMPLETE_SCHEMA_FINAL.sql(main schema)- Remaining migrations…
Method 3: Database URL (Advanced)
Connect directly to your database:Key Migration Files
010_HIRO_COMPLETE_SCHEMA_FINAL.sql
The primary schema migration. Creates:- All core tables (users, customers, reservations, etc.)
- Subscription plans (Free, Starter, Professional, Enterprise)
- Indexes for performance
- Row Level Security (RLS) policies
- Database functions and triggers
- ✅ Idempotent (safe to run multiple times)
- ✅ Uses
IF NOT EXISTSfor tables/indexes - ✅ Uses
ADD COLUMN IF NOT EXISTSfor columns - ✅ Compatible with new and existing databases
015_RLS_DEFINITIVO_HIRO.sql
Configures Row Level Security policies:- Single-tenant security model
- User-based access control
- Read/write policies for all tables
RLS ensures users can only access data they’re authorized to see, even with direct database access.
005_PERMISSIONS_SYSTEM.sql
Sets up the role-based permission system:- Role definitions (super_admin, manager, staff, etc.)
- Module-based permissions
- Location-based access control
Storage Buckets
Hiro CRM uses Supabase Storage for file uploads.Create storage buckets
The migrations automatically create these buckets:
avatars- User profile photoslogos- Brand/location logoslibrary- Document library files
Database Functions
Hiro CRM includes several PostgreSQL functions for business logic:Customer Management
User Management
Dashboard Stats
Extensions
Hiro CRM requires these PostgreSQL extensions (automatically enabled):uuid-ossp- UUID generationpg_trgm- Fuzzy text search (customer names, emails)btree_gin- GIN indexes for array columns
Indexes for Performance
The schema includes 32+ indexes optimized for common queries:Customer Indexes
Reservation Indexes
More indexes are added in
007_PERFORMANCE_INDEXES.sql and 009_ADD_PERFORMANCE_INDEXES.sql.Verification
After running migrations, verify your database setup:Check tables exist
Run this query in SQL Editor:You should see 30+ tables including
customers, reservations, campaigns, etc.Verify subscription plans
- HIRO Free ($0)
- HIRO Starter ($49)
- HIRO Professional ($149)
- HIRO Enterprise ($499)
Troubleshooting
Migration fails with 'relation already exists'
Migration fails with 'relation already exists'
Cause: Migrations already partially applied.Solution: The migrations are idempotent. Simply re-run them. They use
IF NOT EXISTS checks.Permission denied errors
Permission denied errors
Cause: Using anon key instead of service role key.Solution:
- For migrations, use the service role key or database password
- For application, ensure RLS policies are correctly configured
Function 'handle_new_user' not found
Function 'handle_new_user' not found
Cause: Migration not run or failed.Solution: Run
021_FIX_SIGNUP_TRIGGER.sql which creates the user creation trigger.Slow queries
Slow queries
Cause: Missing indexes.Solution:
- Run
007_PERFORMANCE_INDEXES.sql - Run
009_ADD_PERFORMANCE_INDEXES.sql - Check query plans with
EXPLAIN ANALYZE
Backup & Restore
Automated Backups (Free Plan)
Supabase automatically backs up your database daily. Retention:- Free: 7 days
- Pro: 30 days
- Enterprise: Custom
Manual Backup
Restore from Backup
Performance Monitoring
Supabase provides built-in database monitoring:- Go to Database → Query Performance
- View slow queries, most frequent queries
- Optimize based on insights
Next Steps
Seeding Data
Load demo data into your database
Environment Variables
Configure your application environment
Vercel Deployment
Deploy your application to Vercel
Supabase Docs
Official Supabase documentation
