Supabase Quick Access
You are a Supabase expert providing instant access to database operations, authentication patterns, and real-time features.
🚀 LearnFlow Project Quick Reference
Project Details
- Project Name: LearnFlow
- Project Reference ID:
hjivfywgkiwjvpquxndg - Region: Oceania (Sydney)
- Organization: eosdqrnnloqyyotzstpn
- Working Directory:
C:\Users\OEM\CascadeProjects\LearnFlow
⚡ Most Common Commands (Copy-Paste Ready)
Push migrations:
cd C:\Users\OEM\CascadeProjects\LearnFlow; supabase db push
Regenerate types after migration:
cd C:\Users\OEM\CascadeProjects\LearnFlow; supabase gen types typescript --project-id hjivfywgkiwjvpquxndg > src/integrations/supabase/types.ts
Deploy edge function:
cd C:\Users\OEM\CascadeProjects\LearnFlow; supabase functions deploy <function-name> --project-ref hjivfywgkiwjvpquxndg
Check migration status:
cd C:\Users\OEM\CascadeProjects\LearnFlow; supabase migration list
Core Setup
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseKey);
Authentication Patterns
- Sign up with email/password
- Sign in with credentials
- OAuth (Google/GitHub)
- Session management
- Sign out
Database Operations
SELECT
- Fetch all records
- Fetch with filters
- Fetch with sorting
- Fetch with pagination
- Fetch with joins
- Search/full-text search
INSERT
- Single record
- Multiple records
- Batch operations
UPDATE
- Update by ID
- Update with conditions
- Upsert (insert or update)
DELETE
- Delete by ID
- Delete with conditions
Real-Time
- Subscribe to table changes
- Subscribe to specific records
- Handle updates, inserts, deletes
- Proper cleanup on unmount
File Storage
- Upload files
- Download files
- Delete files
- Get public URLs
- Manage permissions
Best Practices
- Always handle errors
- Use TypeScript types
- Implement proper error handling
- Cache queries when appropriate
- Use real-time subscriptions efficiently
- Enable row-level security (RLS)
- Use indexes on frequently queried columns
- Implement pagination for large datasets
- Clean up subscriptions on component unmount
When Using
Provide TypeScript code following these patterns. Include error handling and type safety. Adapt table names and columns to specific use case.
🗄️ Database Migrations
Migration Workflow
1. Create a new migration:
cd C:\Users\OEM\CascadeProjects\LearnFlow
supabase migration new <migration_name>
Creates a new migration file in supabase/migrations/ with timestamp prefix.
2. Push migrations to remote database:
cd C:\Users\OEM\CascadeProjects\LearnFlow
supabase db push
Pushes all local migrations that haven't been applied to the remote database.
3. Check migration status:
supabase migration list
Shows which migrations are applied locally vs remotely.
4. Pull remote migrations:
supabase db pull
Syncs remote migrations to local (if remote has migrations not in local).
5. Repair migration history (if out of sync):
# Mark a migration as reverted
supabase migration repair --status reverted <migration_timestamp>
# Mark a migration as applied
supabase migration repair --status applied <migration_timestamp>
6. Regenerate TypeScript types after migrations:
cd C:\Users\OEM\CascadeProjects\LearnFlow
supabase gen types typescript --project-id hjivfywgkiwjvpquxndg > src/integrations/supabase/types.ts
CRITICAL: Always regenerate types after applying migrations to keep TypeScript types in sync.
Migration Troubleshooting
Problem: "Remote migration versions not found in local migrations directory"
- Solution: Run
supabase db pullto sync, or repair migration history withsupabase migration repair
Problem: "Migration history does not match"
- Solution: Use
supabase migration repairto mark migrations as reverted/applied to match actual state
Problem: Types are out of sync after migration
- Solution: Always run
supabase gen types typescript --project-id hjivfywgkiwjvpquxndg > src/integrations/supabase/types.ts
Migration Best Practices
- Always test migrations locally first (if using local Supabase)
- Regenerate types immediately after pushing migrations
- Use descriptive migration names:
20240101000000_extend_user_profiles_capability_data.sql - Include RLS policies in migrations for new tables
- Add indexes for frequently queried columns
- Use transactions for complex migrations (Supabase handles this automatically)
🚀 Edge Functions Deployment
Deploy Single Function
cd C:\Users\OEM\CascadeProjects\LearnFlow
supabase functions deploy <function-name> --project-ref hjivfywgkiwjvpquxndg
Deploy All Functions
cd C:\Users\OEM\CascadeProjects\LearnFlow
supabase functions deploy --project-ref hjivfywgkiwjvpquxndg
View Function Logs
supabase functions logs <function-name> --project-ref hjivfywgkiwjvpquxndg
View Deployment Dashboard
https://supabase.com/dashboard/project/hjivfywgkiwjvpquxndg/functions
Edge Functions in LearnFlow
generate-learning-content (supabase/functions/generate-learning-content/)
- Handles learning plan generation and step content creation
- Handlers:
plan-generator.ts,content-generator.ts,questions-generator.ts - Deploy:
supabase functions deploy generate-learning-content --project-ref hjivfywgkiwjvpquxndg
edna-sso (supabase/functions/edna-sso/)
- SSO authentication handler
- Deploy:
supabase functions deploy edna-sso --project-ref hjivfywgkiwjvpquxndg
sso-login (supabase/functions/sso-login/)
- SSO login handler
- Deploy:
supabase functions deploy sso-login --project-ref hjivfywgkiwjvpquxndg
text-to-speech (supabase/functions/text-to-speech/)
- Text-to-speech conversion
- Deploy:
supabase functions deploy text-to-speech --project-ref hjivfywgkiwjvpquxndg
openai-tts (supabase/functions/openai-tts/)
- OpenAI TTS integration
- Deploy:
supabase functions deploy openai-tts --project-ref hjivfywgkiwjvpquxndg
generate-mental-model-images (supabase/functions/generate-mental-model-images/)
- Generates mental model diagrams
- Deploy:
supabase functions deploy generate-mental-model-images --project-ref hjivfywgkiwjvpquxndg
generate-ai-insight (supabase/functions/generate-ai-insight/)
- Generates AI insights for Explore Further questions
- Deploy:
supabase functions deploy generate-ai-insight --project-ref hjivfywgkiwjvpquxndg
generate-deep-dive-topics (supabase/functions/generate-deep-dive-topics/)
- Lists related topics
- Deploy:
supabase functions deploy generate-deep-dive-topics --project-ref hjivfywgkiwjvpquxndg
generate-deep-dive-content (supabase/functions/generate-deep-dive-content/)
- Generates deep dive articles
- Deploy:
supabase functions deploy generate-deep-dive-content --project-ref hjivfywgkiwjvpquxndg
📋 Common Commands Reference
Project Management
# List all projects
supabase projects list
# Link to project (already linked for LearnFlow)
supabase link --project-ref hjivfywgkiwjvpquxndg
# Check project status
supabase status
Database Operations
# Push migrations
supabase db push
# Pull migrations
supabase db pull
# Reset local database (WARNING: destructive)
supabase db reset
# Execute SQL directly
supabase db execute "<SQL>" --project-ref hjivfywgkiwjvpquxndg
Type Generation
# Generate TypeScript types
supabase gen types typescript --project-id hjivfywgkiwjvpquxndg > src/integrations/supabase/types.ts
# Generate types for local database
supabase gen types typescript --local > src/integrations/supabase/types.ts
🔧 LearnFlow-Specific Workflows
Complete Migration Workflow
- Create migration:
supabase migration new <name> - Write SQL in the generated file
- Push to remote:
supabase db push - Regenerate types:
supabase gen types typescript --project-id hjivfywgkiwjvpquxndg > src/integrations/supabase/types.ts - Verify types updated correctly
Complete Edge Function Deployment Workflow
- Make changes to function in
supabase/functions/<function-name>/ - Deploy:
supabase functions deploy <function-name> --project-ref hjivfywgkiwjvpquxndg - Check logs if issues:
supabase functions logs <function-name> --project-ref hjivfywgkiwjvpquxndg - Monitor in dashboard: https://supabase.com/dashboard/project/hjivfywgkiwjvpquxndg/functions
generate-learning-content Function Details
The function handles AI-powered learning content generation with three main handlers:
Plan Generator (plan-generator.ts)
- Creates a 10-step differentiated learning plan for any topic
- Returns JSON with step titles and descriptions
- Uses OpenAI with curriculum design expertise
Content Generator (content-generator.ts)
- Generates 600-700 word educational content per step
- Phase-aware: foundational → intermediate → advanced
- Includes content validation (length, truncation checks)
- Caches content in Supabase to avoid regeneration
Questions Generator (questions-generator.ts)
- Creates assessment questions for each step
- Validates and stores in database
All functions use shared OpenAI utilities and database persistence patterns with proper error handling.