-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-table-schema.sql
More file actions
47 lines (41 loc) · 1.95 KB
/
supabase-table-schema.sql
File metadata and controls
47 lines (41 loc) · 1.95 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
-- Verify and create user_settings table if it doesn't exist
CREATE TABLE IF NOT EXISTS public.user_settings (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE UNIQUE,
pomodoro_length INTEGER NOT NULL DEFAULT 25,
short_break_length INTEGER NOT NULL DEFAULT 5,
long_break_length INTEGER NOT NULL DEFAULT 15,
sessions_until_long_break INTEGER NOT NULL DEFAULT 4,
auto_start_breaks BOOLEAN NOT NULL DEFAULT false,
auto_start_pomodoros BOOLEAN NOT NULL DEFAULT false,
sound_enabled BOOLEAN NOT NULL DEFAULT true,
sound_type TEXT NOT NULL DEFAULT 'beep',
notifications_enabled BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- Add RLS policies for user_settings table
ALTER TABLE public.user_settings ENABLE ROW LEVEL SECURITY;
-- Policy for selecting user's own settings
DROP POLICY IF EXISTS "Users can view their own settings" ON public.user_settings;
CREATE POLICY "Users can view their own settings"
ON public.user_settings
FOR SELECT
USING (auth.uid() = user_id);
-- Policy for inserting user's own settings
DROP POLICY IF EXISTS "Users can insert their own settings" ON public.user_settings;
CREATE POLICY "Users can insert their own settings"
ON public.user_settings
FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Policy for updating user's own settings
DROP POLICY IF EXISTS "Users can update their own settings" ON public.user_settings;
CREATE POLICY "Users can update their own settings"
ON public.user_settings
FOR UPDATE
USING (auth.uid() = user_id);
-- Add indexes for performance
CREATE INDEX IF NOT EXISTS user_settings_user_id_idx ON public.user_settings (user_id);
-- Grant permissions
GRANT ALL ON public.user_settings TO service_role;
GRANT SELECT, INSERT, UPDATE ON public.user_settings TO authenticated;