Fix: Audit logs actor mapping and global user relationships (Phase 8 Governance)
Browse files
database/fix_all_user_relationships.sql
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- Global Fix for Schema Cache relationship discovery (Phase 8 Governance)
|
| 2 |
+
-- Ensures all user-related joins work correctly in PostgREST by pointing to public.profiles.
|
| 3 |
+
|
| 4 |
+
-- 1. Projects
|
| 5 |
+
ALTER TABLE public.projects DROP CONSTRAINT IF EXISTS projects_owner_id_fkey;
|
| 6 |
+
ALTER TABLE public.projects ADD CONSTRAINT projects_owner_id_fkey
|
| 7 |
+
FOREIGN KEY (owner_id) REFERENCES public.profiles(id) ON DELETE SET NULL;
|
| 8 |
+
|
| 9 |
+
-- 2. Agents
|
| 10 |
+
ALTER TABLE public.agents DROP CONSTRAINT IF EXISTS agents_user_id_fkey;
|
| 11 |
+
ALTER TABLE public.agents ADD CONSTRAINT agents_user_id_fkey
|
| 12 |
+
FOREIGN KEY (user_id) REFERENCES public.profiles(id) ON DELETE CASCADE;
|
| 13 |
+
|
| 14 |
+
-- 3. Audit Logs
|
| 15 |
+
ALTER TABLE public.audit_logs DROP CONSTRAINT IF EXISTS audit_logs_actor_id_fkey;
|
| 16 |
+
ALTER TABLE public.audit_logs ADD CONSTRAINT audit_logs_actor_id_fkey
|
| 17 |
+
FOREIGN KEY (actor_id) REFERENCES public.profiles(id) ON DELETE SET NULL;
|
| 18 |
+
|
| 19 |
+
-- 4. Agent Templates
|
| 20 |
+
ALTER TABLE public.agent_templates DROP CONSTRAINT IF EXISTS agent_templates_author_id_fkey;
|
| 21 |
+
ALTER TABLE public.agent_templates ADD CONSTRAINT agent_templates_author_id_fkey
|
| 22 |
+
FOREIGN KEY (author_id) REFERENCES public.profiles(id) ON DELETE SET NULL;
|
| 23 |
+
|
| 24 |
+
-- 5. Notify PostgREST
|
| 25 |
+
NOTIFY pgrst, 'reload schema';
|
frontend/src/components/AuditView.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import { supabase } from '../services/supabase';
|
|
| 18 |
interface AuditLog {
|
| 19 |
id: string;
|
| 20 |
created_at: string;
|
| 21 |
-
|
| 22 |
action: string;
|
| 23 |
agent_id: string | null;
|
| 24 |
task_id: string | null;
|
|
@@ -55,7 +55,7 @@ const AuditView: React.FC = () => {
|
|
| 55 |
.from('audit_logs')
|
| 56 |
.select(`
|
| 57 |
*,
|
| 58 |
-
profiles:
|
| 59 |
agents:agent_id(name),
|
| 60 |
tasks:task_id(title)
|
| 61 |
`)
|
|
|
|
| 18 |
interface AuditLog {
|
| 19 |
id: string;
|
| 20 |
created_at: string;
|
| 21 |
+
actor_id: string | null;
|
| 22 |
action: string;
|
| 23 |
agent_id: string | null;
|
| 24 |
task_id: string | null;
|
|
|
|
| 55 |
.from('audit_logs')
|
| 56 |
.select(`
|
| 57 |
*,
|
| 58 |
+
profiles:actor_id(full_name, email),
|
| 59 |
agents:agent_id(name),
|
| 60 |
tasks:task_id(title)
|
| 61 |
`)
|