Database Schema
Hiro CRM uses PostgreSQL as its primary database, managed through Supabase. The schema is optimized for analytics, marketing automation, and real-time customer insights.Core Entities
The database follows a relational model with clear entity relationships:Key Tables
1. Customers
The central table for customer data and CRM functionality.2. Locations
Restaurants and venues within the hospitality group.3. Reservations
Tracking all customer bookings and their status.4. Transactions
Financial transactions and customer spending.5. Hotels
Hotel partners and referral sources.6. Campaigns
Marketing campaigns and customer outreach.7. Loyalty Members
Loyalty program membership and tier tracking.Analytics Tables
Customer Behaviors
Detected behavioral patterns from customer activity.Customer Product History
Detailed consumption tracking for personalization.Database Triggers
Automatic calculations and data synchronization.Update Customer Metrics
Loyalty Tier Calculation
Row Level Security (RLS)
Database-level access control policies.Profile Access
Customer Data Access
Vector Search (AI Ready)
Semantic search capabilities with pgvector extension.Migration Management
Database migrations are stored in/supabase/migrations/ with numbered prefixes:
Performance Optimization
Strategic Indexing
- B-tree indexes for exact matches and range queries
- GIN indexes for array columns (tags, preferences)
- Full-text indexes for search functionality
- Vector indexes for AI-powered semantic search
Query Optimization
Database Functions
Reusable SQL functions for complex operations:Next Steps
Frontend Structure
Learn how the frontend consumes this data
API Routes
Explore API endpoints for data access
