Fix: Database views with auth.users join for email access (Phase 8)
Browse files
database/FINAL_SUPABASE_FIX.sql
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
-- FINAL ROBUST FIX: DATABASE VIEWS
|
| 2 |
-
-- RUN THIS IN SUPABASE SQL EDITOR TO
|
| 3 |
|
| 4 |
-
-- 1. TEAM MEMBERS VIEW
|
| 5 |
CREATE OR REPLACE VIEW public.team_members_with_profiles AS
|
| 6 |
SELECT
|
| 7 |
tm.id,
|
|
@@ -10,9 +10,10 @@ SELECT
|
|
| 10 |
tm.role,
|
| 11 |
tm.created_at,
|
| 12 |
p.full_name,
|
| 13 |
-
|
| 14 |
FROM public.team_members tm
|
| 15 |
-
LEFT JOIN public.profiles p ON tm.user_id = p.id
|
|
|
|
| 16 |
|
| 17 |
GRANT SELECT ON public.team_members_with_profiles TO authenticated;
|
| 18 |
|
|
@@ -27,11 +28,12 @@ SELECT
|
|
| 27 |
al.metadata,
|
| 28 |
al.created_at,
|
| 29 |
p.full_name AS actor_name,
|
| 30 |
-
|
| 31 |
ag.name AS agent_name,
|
| 32 |
t.title AS task_title
|
| 33 |
FROM public.audit_logs al
|
| 34 |
LEFT JOIN public.profiles p ON al.user_id = p.id
|
|
|
|
| 35 |
LEFT JOIN public.agents ag ON al.agent_id = ag.id
|
| 36 |
LEFT JOIN public.tasks t ON al.task_id = t.id;
|
| 37 |
|
|
|
|
| 1 |
+
-- FINAL ROBUST FIX: DATABASE VIEWS WITH AUTH JOIN (Phase 8)
|
| 2 |
+
-- RUN THIS IN SUPABASE SQL EDITOR TO RESOLVE ALL GOVERNANCE ISSUES
|
| 3 |
|
| 4 |
+
-- 1. TEAM MEMBERS VIEW (Joining auth.users for guaranteed email)
|
| 5 |
CREATE OR REPLACE VIEW public.team_members_with_profiles AS
|
| 6 |
SELECT
|
| 7 |
tm.id,
|
|
|
|
| 10 |
tm.role,
|
| 11 |
tm.created_at,
|
| 12 |
p.full_name,
|
| 13 |
+
u.email
|
| 14 |
FROM public.team_members tm
|
| 15 |
+
LEFT JOIN public.profiles p ON tm.user_id = p.id
|
| 16 |
+
LEFT JOIN auth.users u ON tm.user_id = u.id;
|
| 17 |
|
| 18 |
GRANT SELECT ON public.team_members_with_profiles TO authenticated;
|
| 19 |
|
|
|
|
| 28 |
al.metadata,
|
| 29 |
al.created_at,
|
| 30 |
p.full_name AS actor_name,
|
| 31 |
+
u.email AS actor_email,
|
| 32 |
ag.name AS agent_name,
|
| 33 |
t.title AS task_title
|
| 34 |
FROM public.audit_logs al
|
| 35 |
LEFT JOIN public.profiles p ON al.user_id = p.id
|
| 36 |
+
LEFT JOIN auth.users u ON al.user_id = u.id
|
| 37 |
LEFT JOIN public.agents ag ON al.agent_id = ag.id
|
| 38 |
LEFT JOIN public.tasks t ON al.task_id = t.id;
|
| 39 |
|