Schema Overview
Cabina uses PostgreSQL via Supabase with the following core tables:- profiles - User accounts and credits
- partners - White-label resellers (B2B)
- clients - Partner’s customers
- events - Photo booth events
- generations - AI-generated photos
- api_key_pool - Load-balanced AI API keys
- payment_notifications - Mercado Pago webhooks
- styles_metadata - Available photo styles
- identity_prompts - AI prompts for styles
Core Tables
profiles
User accounts for the B2C app and authenticated users.Primary key, references
auth.users(id)User’s email address
Available credits for B2C users (Modelo A)
Total number of photos generated by this user
Admin flag (Leo = true)
User role:
'user', 'partner', 'client', or 'master'Unique referral code for this user
References the user who referred this account
partners
White-label resellers who create events for their clients.Primary key
Partner display name
Links partner to a login account in
profilesTotal credits purchased from Master
Credits consumed across all partner events
White-label configuration:
clients
Partner’s end customers who manage specific events.Foreign key to
partners(id)Array of style IDs this client can use
events
Photo booth events with allocated credits and configuration.Unique URL slug for the event (e.g.,
quince-sofia-2024)Used in URLs: /?event=quince-sofia-2024Total credits assigned to this event
Credits consumed by guest generationsUpdated atomically via
increment_event_credit RPCArray of style IDs enabled for this eventExample:
['pb_a', 'suit_b', 'jhonw_c']Event branding and settings:
Simple PIN for client dashboard access
generations
AI-generated photos from both B2C users and event guests.User who generated this (B2C model)Nullable - event guests don’t have accounts
Event this generation belongs to (B2B model)Nullable - B2C generations have no event
AI model/style identifier (e.g.,
pb_a, suit_b)URL to the generated image in Supabase Storage or external CDN
Credit Model Logic:
- If
user_idis set: deduct fromprofiles.credits - If
event_idis set: deduct fromevents.credits_allocated(atomic RPC)
api_key_pool
Load balancer for AI API keys (Kie.ai).Kie.ai API key
Whether this key should be used in rotation
Timestamp of last usage (for least-recently-used selection)
Total number of times this key has been used
The
cabina-vision edge function selects the least recently used active key for each generation request.payment_notifications
Webhook events from Mercado Pago.Unique payment ID from Mercado Pago
User who made the purchase
Number of credits granted for this payment
Full webhook payload from Mercado Pago
styles_metadata
Available photo styles and their metadata.Style identifier (e.g.,
pb_a, suit_b)Style pack name (e.g., “Peaky Blinders”, “La Ley de los Audaces”)
Searchable tags:
['gangster', 'vintage', 'cap', 'whiskey']Whether this style requires premium access
identity_prompts
AI prompts for each style.Matches
styles_metadata.idFull AI prompt for image generationExample:
Database Functions
increment_event_credit
Atomically increments event credit usage.Indexes
Key indexes for performance:Relationships
Storage Buckets
user_photos
- Purpose: Temporary storage for uploaded user photos
- Public: No
- RLS: Users can only access their own uploads
generations
- Purpose: Final AI-generated images
- Public: Yes
- Path:
results/{user_id}_{timestamp}.png
event_assets
- Purpose: Event logos and branding
- Public: Yes
- Path:
events/{event_id}/logo.png
Next Steps
Migrations
Learn how to manage database migrations
RLS Policies
Understand Row Level Security