Files
thrilltrack-explorer/supabase/migrations/20251029132334_a9914cea-ac16-4114-8c20-07f91f0e57bb.sql
gpt-engineer-app[bot] 32354548ce Fix foreign key constraints
2025-10-29 13:23:45 +00:00

37 lines
1.2 KiB
SQL

-- Drop existing foreign keys that point to auth.users
ALTER TABLE public.content_submissions
DROP CONSTRAINT IF EXISTS content_submissions_user_id_fkey;
ALTER TABLE public.content_submissions
DROP CONSTRAINT IF EXISTS content_submissions_reviewer_id_fkey;
ALTER TABLE public.content_submissions
DROP CONSTRAINT IF EXISTS content_submissions_assigned_to_fkey;
ALTER TABLE public.content_submissions
DROP CONSTRAINT IF EXISTS content_submissions_escalated_by_fkey;
-- Create new foreign keys pointing to profiles table
ALTER TABLE public.content_submissions
ADD CONSTRAINT content_submissions_user_id_fkey
FOREIGN KEY (user_id)
REFERENCES public.profiles(user_id)
ON DELETE CASCADE;
ALTER TABLE public.content_submissions
ADD CONSTRAINT content_submissions_reviewer_id_fkey
FOREIGN KEY (reviewer_id)
REFERENCES public.profiles(user_id)
ON DELETE SET NULL;
ALTER TABLE public.content_submissions
ADD CONSTRAINT content_submissions_assigned_to_fkey
FOREIGN KEY (assigned_to)
REFERENCES public.profiles(user_id)
ON DELETE SET NULL;
ALTER TABLE public.content_submissions
ADD CONSTRAINT content_submissions_escalated_by_fkey
FOREIGN KEY (escalated_by)
REFERENCES public.profiles(user_id)
ON DELETE SET NULL;