mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
21 lines
594 B
SQL
21 lines
594 B
SQL
-- Drop existing foreign key constraint with RESTRICT
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (
|
|
SELECT 1
|
|
FROM pg_constraint
|
|
WHERE conname = 'fk_project_chickins_kandang'
|
|
AND conrelid = 'project_chickins'::regclass
|
|
) THEN
|
|
ALTER TABLE project_chickins
|
|
DROP CONSTRAINT fk_project_chickins_kandang;
|
|
END IF;
|
|
END $$;
|
|
|
|
-- Add new foreign key constraint with CASCADE delete
|
|
ALTER TABLE project_chickins
|
|
ADD CONSTRAINT fk_project_chickins_kandang
|
|
FOREIGN KEY (project_flock_kandang_id)
|
|
REFERENCES project_flock_kandangs(id)
|
|
ON DELETE CASCADE ON UPDATE CASCADE;
|