-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_feedback_schema.sql
More file actions
48 lines (44 loc) · 1.28 KB
/
Copy pathupdate_feedback_schema.sql
File metadata and controls
48 lines (44 loc) · 1.28 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
-- Add reply columns if they don't exist
alter table feedback
add column if not exists admin_reply text,
add column if not exists reply_created_at timestamptz;
-- Refresh Policies
drop policy if exists "Users can view own feedback" on feedback;
drop policy if exists "Users can select own feedback" on feedback;
drop policy if exists "Admins can view all feedback" on feedback;
drop policy if exists "Admins can update feedback status" on feedback;
drop policy if exists "Admins can update feedback" on feedback;
-- Policy: Authenticated users can view their own feedback
create policy "Users can view own feedback"
on feedback for select
to authenticated
using (auth.uid() = user_id);
-- Policy: Admin can 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 (reply, status change)
create policy "Admins can update feedback"
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
)
);