-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_progress_migration.sql
More file actions
29 lines (23 loc) · 1.15 KB
/
Copy pathtest_progress_migration.sql
File metadata and controls
29 lines (23 loc) · 1.15 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
-- Create test_progress table to track user progress in tests
CREATE TABLE IF NOT EXISTS test_progress (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
test_session_id UUID NOT NULL REFERENCES test_sessions(id) ON DELETE CASCADE,
current_case_index INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(user_id, test_session_id)
);
-- Create index for faster lookups
CREATE INDEX IF NOT EXISTS idx_test_progress_user_session ON test_progress(user_id, test_session_id);
-- Enable RLS
ALTER TABLE test_progress ENABLE ROW LEVEL SECURITY;
-- Create RLS policies
CREATE POLICY "Users can view their own progress" ON test_progress
FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY "Users can insert their own progress" ON test_progress
FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update their own progress" ON test_progress
FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY "Users can delete their own progress" ON test_progress
FOR DELETE USING (auth.uid() = user_id);