Production Database Migrations
Current Status
The following migrations need to be applied to your production Supabase database:
- 015_add_tone_packs.sql - Creates tone packs tables
- 016_add_drops_currency.sql - Adds drops currency system
- 017_add_token_tracking.sql - Adds token tracking and conversion rates
How to Apply Migrations
Option 1: Supabase Dashboard (Recommended)
-
Go to your Supabase Dashboard
- Navigate to https://supabase.com/dashboard
- Select your project
-
Open SQL Editor
- Click on "SQL Editor" in the left sidebar
- Click "New query"
-
Run Each Migration in Order
Migration 015: Tone Packs
- Copy the entire contents of
supabase/migrations/015_add_tone_packs.sql - Paste into SQL Editor
- Click "Run" (or press Cmd/Ctrl + Enter)
- Wait for success message
Migration 016: Drops Currency
- Copy the entire contents of
supabase/migrations/016_add_drops_currency.sql - Paste into SQL Editor
- Click "Run"
- Wait for success message
Migration 017: Token Tracking
- Copy the entire contents of
supabase/migrations/017_add_token_tracking.sql - Paste into SQL Editor
- Click "Run"
- Wait for success message
- Copy the entire contents of
-
Verify
- Go to "Table Editor" in Supabase
- You should see these new tables:
tone_packstone_pack_imagestone_pack_sharesdrop_transactionsmonthly_dropstone_pack_purchasestoken_usagecurrency_conversion_rates
- The
profilestable should have adrops_balancecolumn - The
tone_packstable should have aprice_dropscolumn
Option 2: Supabase CLI
If you have Supabase CLI installed:
# Install Supabase CLI (if not installed)
npm install -g supabase
# Link to your project
supabase link --project-ref your-project-ref
# Push all migrations
supabase db push
What Each Migration Does
Migration 015: Tone Packs
- Creates
tone_packstable for tone pack metadata - Creates
tone_pack_imagestable for tone-to-image mappings - Creates
tone_pack_sharestable for sharing - Sets up RLS policies
Migration 016: Drops Currency
- Adds
drops_balancecolumn toprofilestable - Creates
drop_transactionstable for transaction history - Creates
monthly_dropstable for tracking monthly awards - Adds
price_dropscolumn totone_packstable - Creates
tone_pack_purchasestable - Sets up database trigger for signup bonus (50 drops)
Migration 017: Token Tracking
- Creates
token_usagetable for tracking OpenAI API usage - Creates
currency_conversion_ratestable for managing conversion rates - Creates
get_user_token_usage_monthly()function for monthly aggregation - Sets up indexes for performance
After Running Migrations
Once all migrations are applied:
- Restart your Railway backend (if needed)
- Test the features:
- Create a tone pack in settings
- Check your drops balance
- View token usage in admin panel (if super admin)
Troubleshooting
If you get errors:
- "relation already exists" - The table already exists, you can skip that migration
- "column already exists" - The column already exists, safe to ignore
- "permission denied" - Make sure you're using the SQL Editor (not the Table Editor)
- "function already exists" - The function already exists, safe to ignore
- "policy already exists" - The policy already exists, safe to ignore
Most migrations use CREATE IF NOT EXISTS or ADD COLUMN IF NOT EXISTS so they're safe to run multiple times.
Quick Verification Query
Run this in SQL Editor to verify all tables exist:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name IN (
'tone_packs',
'tone_pack_images',
'tone_pack_shares',
'drop_transactions',
'monthly_drops',
'tone_pack_purchases',
'token_usage',
'currency_conversion_rates'
)
ORDER BY table_name;
You should see all 8 tables listed.