Fix foreign key constraints

This commit is contained in:
gpt-engineer-app[bot]
2025-10-29 13:23:45 +00:00
parent 3e0c4db0a1
commit 32354548ce
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
-- 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;