forked from syedahmedkhaderi/AlgoBuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_setup.sql
More file actions
146 lines (117 loc) · 4.97 KB
/
Copy pathsupabase_setup.sql
File metadata and controls
146 lines (117 loc) · 4.97 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- Add joined_community column to user_profiles for Join Community Button
ALTER TABLE user_profiles ADD COLUMN IF NOT EXISTS joined_community BOOLEAN DEFAULT false;
-- Create community_contributors table for the Contributors Grid section
CREATE TABLE IF NOT EXISTS community_contributors (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
avatar_url TEXT,
role TEXT DEFAULT 'Contributor',
github_url TEXT,
"order" INTEGER DEFAULT 0
);
ALTER TABLE community_contributors ENABLE ROW LEVEL SECURITY;
-- Allow public read access (unauthenticated users can view contributors)
CREATE POLICY "Allow public read access" ON community_contributors
FOR SELECT
USING (true);
-- ====================================================================
-- RLS Policies for user_progress table
-- ====================================================================
ALTER TABLE user_progress ENABLE ROW LEVEL SECURITY;
-- Users can read only their own progress
CREATE POLICY "Users can read own progress" ON user_progress
FOR SELECT
USING (auth.uid() = user_id);
-- Users can insert their own progress
CREATE POLICY "Users can insert own progress" ON user_progress
FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Users can update their own progress
CREATE POLICY "Users can update own progress" ON user_progress
FOR UPDATE
USING (auth.uid() = user_id);
-- ====================================================================
-- RLS Policies for problem_bookmarks table
-- ====================================================================
ALTER TABLE problem_bookmarks ENABLE ROW LEVEL SECURITY;
-- Users can read only their own bookmarks
CREATE POLICY "Users can read own bookmarks" ON problem_bookmarks
FOR SELECT
USING (auth.uid() = user_id);
-- Users can insert their own bookmarks
CREATE POLICY "Users can insert own bookmarks" ON problem_bookmarks
FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Users can update their own bookmarks
CREATE POLICY "Users can update own bookmarks" ON problem_bookmarks
FOR UPDATE
USING (auth.uid() = user_id);
-- Users can delete their own bookmarks
CREATE POLICY "Users can delete own bookmarks" ON problem_bookmarks
FOR DELETE
USING (auth.uid() = user_id);
-- ====================================================================
-- RLS Policies for user_profiles table
-- ====================================================================
ALTER TABLE user_profiles ENABLE ROW LEVEL SECURITY;
-- Users can read their own profile
CREATE POLICY "Users can read own profile" ON user_profiles
FOR SELECT
USING (auth.uid() = id);
-- Users can upsert their own profile
CREATE POLICY "Users can upsert own profile" ON user_profiles
FOR INSERT
WITH CHECK (auth.uid() = id);
CREATE POLICY "Users can update own profile" ON user_profiles
FOR UPDATE
USING (auth.uid() = id);
-- ====================================================================
-- RLS Policies for user_activity table
-- ====================================================================
ALTER TABLE user_activity ENABLE ROW LEVEL SECURITY;
-- Users can read their own activity
CREATE POLICY "Users can read own activity" ON user_activity
FOR SELECT
USING (auth.uid() = user_id);
-- Users can insert their own activity
CREATE POLICY "Users can insert own activity" ON user_activity
FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Users can update their own activity
CREATE POLICY "Users can update own activity" ON user_activity
FOR UPDATE
USING (auth.uid() = user_id);
-- ====================================================================
-- pending_messages table for SMTP quota fallback
-- ====================================================================
CREATE TABLE IF NOT EXISTS pending_messages (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
type TEXT NOT NULL CHECK (type IN ('contact', 'review')),
payload JSONB NOT NULL,
created_at TIMESTAMPTZ DEFAULT now(),
sent_at TIMESTAMPTZ
);
ALTER TABLE pending_messages ENABLE ROW LEVEL SECURITY;
-- Allow the service role (admin) to insert and read pending messages
CREATE POLICY "Service role can insert pending_messages" ON pending_messages
FOR INSERT
WITH CHECK (true);
CREATE POLICY "Service role can read pending_messages" ON pending_messages
FOR SELECT
USING (true);
CREATE POLICY "Service role can update pending_messages" ON pending_messages
FOR UPDATE
USING (true);
-- ====================================================================
-- newsletter_subscriptions table for Footer Newsletter
-- ====================================================================
CREATE TABLE IF NOT EXISTS newsletter_subscriptions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT UNIQUE NOT NULL,
subscribed_at TIMESTAMPTZ DEFAULT now(),
status TEXT DEFAULT 'active'
);
ALTER TABLE newsletter_subscriptions ENABLE ROW LEVEL SECURITY;
-- Allow the service role to manage subscriptions
CREATE POLICY "Service role can manage newsletter_subscriptions" ON newsletter_subscriptions
USING (true) WITH CHECK (true);