Fix: Relationship discovery for team_members profile join (Phase 8 Governance)
Browse files
database/fix_team_members_relationship.sql
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- Fix for Schema Cache relationship error (Phase 8 Governance)
|
| 2 |
+
-- This migration ensures PostgREST can discover the relationship between team_members and profiles.
|
| 3 |
+
|
| 4 |
+
-- 1. Update foreign key to point to public.profiles instead of auth.users
|
| 5 |
+
-- They both share the same UUID, but pointing to public schema helps PostgREST discovery.
|
| 6 |
+
ALTER TABLE public.team_members
|
| 7 |
+
DROP CONSTRAINT IF EXISTS team_members_user_id_fkey;
|
| 8 |
+
|
| 9 |
+
ALTER TABLE public.team_members
|
| 10 |
+
ADD CONSTRAINT team_members_user_id_fkey
|
| 11 |
+
FOREIGN KEY (user_id) REFERENCES public.profiles(id) ON DELETE CASCADE;
|
| 12 |
+
|
| 13 |
+
-- 2. Ensure RLS doesn't block the join
|
| 14 |
+
-- (Already handled in fix_teams_rls_governance, but double checking)
|
| 15 |
+
GRANT SELECT ON public.profiles TO authenticated;
|
| 16 |
+
|
| 17 |
+
-- 3. Notify PostgREST to reload schema
|
| 18 |
+
NOTIFY pgrst, 'reload schema';
|