chore: heygermany customer project
This commit is contained in:
54
db/postgres/0017-cascade-delete-document-references.sql
Normal file
54
db/postgres/0017-cascade-delete-document-references.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
-- Add ON DELETE CASCADE to all foreign key constraints referencing candidate_document
|
||||
-- This allows deleting documents without violating foreign key constraints
|
||||
|
||||
-- Drop and recreate foreign key constraints with ON DELETE CASCADE
|
||||
|
||||
-- 1. candidate_education.source_document_id
|
||||
ALTER TABLE app.candidate_education
|
||||
DROP CONSTRAINT IF EXISTS candidate_education_source_document_id_fkey;
|
||||
|
||||
ALTER TABLE app.candidate_education
|
||||
ADD CONSTRAINT candidate_education_source_document_id_fkey
|
||||
FOREIGN KEY (source_document_id)
|
||||
REFERENCES app.candidate_document(document_id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
-- 2. candidate_transcript.source_document_id
|
||||
ALTER TABLE app.candidate_transcript
|
||||
DROP CONSTRAINT IF EXISTS candidate_transcript_source_document_id_fkey;
|
||||
|
||||
ALTER TABLE app.candidate_transcript
|
||||
ADD CONSTRAINT candidate_transcript_source_document_id_fkey
|
||||
FOREIGN KEY (source_document_id)
|
||||
REFERENCES app.candidate_document(document_id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
-- 3. candidate_license.source_document_id
|
||||
ALTER TABLE app.candidate_license
|
||||
DROP CONSTRAINT IF EXISTS candidate_license_source_document_id_fkey;
|
||||
|
||||
ALTER TABLE app.candidate_license
|
||||
ADD CONSTRAINT candidate_license_source_document_id_fkey
|
||||
FOREIGN KEY (source_document_id)
|
||||
REFERENCES app.candidate_document(document_id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
-- 4. candidate_language.source_document_id
|
||||
ALTER TABLE app.candidate_language
|
||||
DROP CONSTRAINT IF EXISTS candidate_language_source_document_id_fkey;
|
||||
|
||||
ALTER TABLE app.candidate_language
|
||||
ADD CONSTRAINT candidate_language_source_document_id_fkey
|
||||
FOREIGN KEY (source_document_id)
|
||||
REFERENCES app.candidate_document(document_id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
-- 5. candidate_experience.source_document_id
|
||||
ALTER TABLE app.candidate_experience
|
||||
DROP CONSTRAINT IF EXISTS candidate_experience_source_document_id_fkey;
|
||||
|
||||
ALTER TABLE app.candidate_experience
|
||||
ADD CONSTRAINT candidate_experience_source_document_id_fkey
|
||||
FOREIGN KEY (source_document_id)
|
||||
REFERENCES app.candidate_document(document_id)
|
||||
ON DELETE CASCADE;
|
||||
Reference in New Issue
Block a user