Pulastya B commited on
Commit
a220eb5
·
1 Parent(s): 1d8f0c9

Add Supabase setup documentation

Browse files
Files changed (1) hide show
  1. SUPABASE_SETUP.md +136 -0
SUPABASE_SETUP.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Supabase Database Setup
2
+
3
+ This document explains how to set up the Supabase tables for user authentication and analytics.
4
+
5
+ ## Tables Created
6
+
7
+ ### 1. user_profiles
8
+ Stores user onboarding data from the multi-step signup form.
9
+
10
+ **Columns:**
11
+ - `id` (UUID) - Primary key
12
+ - `user_id` (UUID) - References auth.users(id), unique
13
+ - `name` (TEXT) - Full name
14
+ - `email` (TEXT) - Email address
15
+ - `primary_goal` (TEXT) - User's primary goal
16
+ - `target_outcome` (TEXT) - What they want to achieve
17
+ - `data_types` (TEXT[]) - Array of data types they work with
18
+ - `profession` (TEXT) - Job title/role
19
+ - `experience` (TEXT) - Experience level
20
+ - `industry` (TEXT) - Industry they work in
21
+ - `onboarding_completed` (BOOLEAN) - Whether they finished onboarding
22
+ - `created_at` (TIMESTAMP) - Created timestamp
23
+ - `updated_at` (TIMESTAMP) - Last updated timestamp
24
+
25
+ ### 2. usage_analytics
26
+ Tracks each query/interaction with the agent.
27
+
28
+ **Columns:**
29
+ - `id` (UUID) - Primary key
30
+ - `user_id` (TEXT) - User identifier
31
+ - `user_email` (TEXT) - User email
32
+ - `session_id` (TEXT) - Session UUID
33
+ - `query` (TEXT) - The user's query
34
+ - `agent_used` (TEXT) - Which specialist agent handled it
35
+ - `tools_executed` (TEXT[]) - Array of tools used
36
+ - `tokens_used` (INTEGER) - Tokens consumed
37
+ - `duration_ms` (INTEGER) - Time taken
38
+ - `success` (BOOLEAN) - Whether it succeeded
39
+ - `error_message` (TEXT) - Error details if failed
40
+ - `created_at` (TIMESTAMP) - When the query was made
41
+
42
+ ### 3. user_sessions
43
+ Tracks user sessions for analytics.
44
+
45
+ **Columns:**
46
+ - `id` (UUID) - Primary key
47
+ - `user_id` (TEXT) - User identifier
48
+ - `user_email` (TEXT) - User email
49
+ - `started_at` (TIMESTAMP) - Session start time
50
+ - `ended_at` (TIMESTAMP) - Session end time
51
+ - `queries_count` (INTEGER) - Number of queries in session
52
+ - `browser_info` (TEXT) - User agent string
53
+ - `created_at` (TIMESTAMP) - Created timestamp
54
+
55
+ ## Setup Instructions
56
+
57
+ ### Step 1: Create Tables
58
+
59
+ 1. Go to your Supabase project: https://supabase.com/dashboard
60
+ 2. Click on **SQL Editor** in the left sidebar
61
+ 3. Click **New Query**
62
+ 4. Copy the entire contents of `supabase_schema.sql`
63
+ 5. Paste into the query editor
64
+ 6. Click **Run** to execute
65
+
66
+ ### Step 2: Verify Tables
67
+
68
+ 1. Click on **Table Editor** in the left sidebar
69
+ 2. You should see:
70
+ - `user_profiles`
71
+ - `usage_analytics`
72
+ - `user_sessions`
73
+
74
+ ### Step 3: Test Authentication
75
+
76
+ 1. Sign up via the app (email/password or OAuth)
77
+ 2. Complete the multi-step onboarding form
78
+ 3. Check the `user_profiles` table - you should see your data
79
+ 4. Make a query to the agent
80
+ 5. Check `usage_analytics` and `user_sessions` tables for tracking data
81
+
82
+ ## Row Level Security (RLS)
83
+
84
+ The tables have RLS enabled with policies:
85
+ - **user_profiles**: Users can only read/insert/update their own profile
86
+ - **usage_analytics** and **user_sessions**: No RLS (for admin analytics)
87
+
88
+ ## Querying Analytics
89
+
90
+ ### Get total users
91
+ ```sql
92
+ SELECT COUNT(DISTINCT user_id) FROM user_profiles;
93
+ ```
94
+
95
+ ### Get queries in last 7 days
96
+ ```sql
97
+ SELECT COUNT(*)
98
+ FROM usage_analytics
99
+ WHERE created_at >= NOW() - INTERVAL '7 days';
100
+ ```
101
+
102
+ ### Get most active users
103
+ ```sql
104
+ SELECT user_email, COUNT(*) as query_count
105
+ FROM usage_analytics
106
+ WHERE created_at >= NOW() - INTERVAL '30 days'
107
+ GROUP BY user_email
108
+ ORDER BY query_count DESC
109
+ LIMIT 10;
110
+ ```
111
+
112
+ ### Get success rate
113
+ ```sql
114
+ SELECT
115
+ COUNT(*) as total_queries,
116
+ SUM(CASE WHEN success THEN 1 ELSE 0 END) as successful,
117
+ ROUND(100.0 * SUM(CASE WHEN success THEN 1 ELSE 0 END) / COUNT(*), 2) as success_rate
118
+ FROM usage_analytics;
119
+ ```
120
+
121
+ ## Troubleshooting
122
+
123
+ ### User profile not saving
124
+ - Check that Supabase URL and Anon Key are set as HuggingFace Secrets
125
+ - Check browser console for errors
126
+ - Verify the `user_profiles` table exists and RLS policies are correct
127
+
128
+ ### OAuth users not showing onboarding form
129
+ - This is expected! OAuth users are prompted to complete the form after signing in
130
+ - The form auto-fills their email and name from OAuth data
131
+ - They only fill in: goals, profession, industry, experience
132
+
133
+ ### Analytics not tracking
134
+ - Check that `usage_analytics` and `user_sessions` tables exist
135
+ - Verify no RLS blocking inserts (they should have no RLS for admin use)
136
+ - Check network tab for failed API calls to Supabase