Spaces:
Running
Running
Supabase Database Setup
This document explains how to set up the Supabase tables for user authentication and analytics.
Tables Created
1. user_profiles
Stores user onboarding data from the multi-step signup form.
Columns:
id(UUID) - Primary keyuser_id(UUID) - References auth.users(id), uniquename(TEXT) - Full nameemail(TEXT) - Email addressprimary_goal(TEXT) - User's primary goaltarget_outcome(TEXT) - What they want to achievedata_types(TEXT[]) - Array of data types they work withprofession(TEXT) - Job title/roleexperience(TEXT) - Experience levelindustry(TEXT) - Industry they work inonboarding_completed(BOOLEAN) - Whether they finished onboardingcreated_at(TIMESTAMP) - Created timestampupdated_at(TIMESTAMP) - Last updated timestamp
2. usage_analytics
Tracks each query/interaction with the agent.
Columns:
id(UUID) - Primary keyuser_id(TEXT) - User identifieruser_email(TEXT) - User emailsession_id(TEXT) - Session UUIDquery(TEXT) - The user's queryagent_used(TEXT) - Which specialist agent handled ittools_executed(TEXT[]) - Array of tools usedtokens_used(INTEGER) - Tokens consumedduration_ms(INTEGER) - Time takensuccess(BOOLEAN) - Whether it succeedederror_message(TEXT) - Error details if failedcreated_at(TIMESTAMP) - When the query was made
3. user_sessions
Tracks user sessions for analytics.
Columns:
id(UUID) - Primary keyuser_id(TEXT) - User identifieruser_email(TEXT) - User emailstarted_at(TIMESTAMP) - Session start timeended_at(TIMESTAMP) - Session end timequeries_count(INTEGER) - Number of queries in sessionbrowser_info(TEXT) - User agent stringcreated_at(TIMESTAMP) - Created timestamp
Setup Instructions
Step 1: Create Tables
- Go to your Supabase project: https://supabase.com/dashboard
- Click on SQL Editor in the left sidebar
- Click New Query
- Copy the entire contents of
supabase_schema.sql - Paste into the query editor
- Click Run to execute
Step 2: Verify Tables
- Click on Table Editor in the left sidebar
- You should see:
user_profilesusage_analyticsuser_sessions
Step 3: Test Authentication
- Sign up via the app (email/password or OAuth)
- Complete the multi-step onboarding form
- Check the
user_profilestable - you should see your data - Make a query to the agent
- Check
usage_analyticsanduser_sessionstables for tracking data
Row Level Security (RLS)
The tables have RLS enabled with policies:
- user_profiles: Users can only read/insert/update their own profile
- usage_analytics and user_sessions: No RLS (for admin analytics)
Querying Analytics
Get total users
SELECT COUNT(DISTINCT user_id) FROM user_profiles;
Get queries in last 7 days
SELECT COUNT(*)
FROM usage_analytics
WHERE created_at >= NOW() - INTERVAL '7 days';
Get most active users
SELECT user_email, COUNT(*) as query_count
FROM usage_analytics
WHERE created_at >= NOW() - INTERVAL '30 days'
GROUP BY user_email
ORDER BY query_count DESC
LIMIT 10;
Get success rate
SELECT
COUNT(*) as total_queries,
SUM(CASE WHEN success THEN 1 ELSE 0 END) as successful,
ROUND(100.0 * SUM(CASE WHEN success THEN 1 ELSE 0 END) / COUNT(*), 2) as success_rate
FROM usage_analytics;
Troubleshooting
User profile not saving
- Check that Supabase URL and Anon Key are set as HuggingFace Secrets
- Check browser console for errors
- Verify the
user_profilestable exists and RLS policies are correct
OAuth users not showing onboarding form
- This is expected! OAuth users are prompted to complete the form after signing in
- The form auto-fills their email and name from OAuth data
- They only fill in: goals, profession, industry, experience
Analytics not tracking
- Check that
usage_analyticsanduser_sessionstables exist - Verify no RLS blocking inserts (they should have no RLS for admin use)
- Check network tab for failed API calls to Supabase