-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
48 lines (39 loc) · 2.04 KB
/
supabase_schema.sql
File metadata and controls
48 lines (39 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- Exogram / RichardEwing.io Supabase Schema for Longitudinal Tool Tracking
-- Execute this directly in the Supabase SQL Editor
CREATE TABLE IF NOT EXISTS public.user_tool_runs (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id TEXT NOT NULL, -- Corresponds to Clerk user ID (e.g., user_2k...)
tool_id TEXT NOT NULL, -- e.g., 'APER', 'AUEB', 'EV-SE'
run_data JSONB NOT NULL, -- The original inputs provided by the user
output_metrics JSONB DEFAULT '{}'::jsonb, -- The resulting calculations/margins
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL
);
-- Enable RLS (Service Role Key bypasses this, public anon key is blocked)
ALTER TABLE public.user_tool_runs ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Service Role Only" ON public.user_tool_runs FOR ALL USING (false);
-- Index for scalable dashboard retrieval
CREATE INDEX IF NOT EXISTS idx_user_tool_runs_user_id ON public.user_tool_runs(user_id);
-- Note: No Row Level Security (RLS) policies are active.
-- Verification happens completely server-side via Clerk's auth() method
-- executing through the Service Role Key.
CREATE TABLE IF NOT EXISTS public.user_content_progress (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id TEXT NOT NULL,
content_type TEXT NOT NULL,
content_id TEXT NOT NULL,
progress_percentage INTEGER DEFAULT 0,
is_completed BOOLEAN DEFAULT false,
last_accessed TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
UNIQUE(user_id, content_id)
);
-- Enable RLS (Service Role Key bypasses this, public anon key is blocked)
ALTER TABLE public.user_content_progress ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Service Role Only" ON public.user_content_progress FOR ALL USING (false);
-- If public.tool_runs exists from an older iteration, secure it as well.
DO $$
BEGIN
IF EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'tool_runs') THEN
EXECUTE 'ALTER TABLE public.tool_runs ENABLE ROW LEVEL SECURITY;';
EXECUTE 'CREATE POLICY "Service Role Only" ON public.tool_runs FOR ALL USING (false);';
END IF;
END $$;