-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedback_setup.sql
More file actions
50 lines (46 loc) · 1.3 KB
/
feedback_setup.sql
File metadata and controls
50 lines (46 loc) · 1.3 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
-- Create Feedback Table
create table if not exists feedback (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users(id) not null,
message text not null,
type text not null check (type in ('feedback', 'feature_request', 'bug')),
created_at timestamptz default now(),
status text not null default 'new' check (status in ('new', 'read', 'completed')),
user_email text -- Optional: store email for easier contact
);
-- Enable RLS
alter table feedback enable row level security;
-- Policy: Authenticated users can insert their own feedback
create policy "Users can insert their own feedback"
on feedback for insert
to authenticated
with check (auth.uid() = user_id);
-- Policy: Admin can select/view all feedback (role-based)
create policy "Admins can view all feedback"
on feedback for select
to authenticated
using (
exists (
select 1 from profiles p
where p.id = auth.uid()
and p.is_admin = true
)
);
-- Policy: Admin can update feedback (e.g. status)
create policy "Admins can update feedback status"
on feedback for update
to authenticated
using (
exists (
select 1 from profiles p
where p.id = auth.uid()
and p.is_admin = true
)
)
with check (
exists (
select 1 from profiles p
where p.id = auth.uid()
and p.is_admin = true
)
);