From 05e9b0992889881df53e62db2940a9d04d482fea Mon Sep 17 00:00:00 2001 From: Sarah Roberts Date: Wed, 7 Jun 2023 12:45:36 -0700 Subject: [PATCH] CORE-1906: automatically delete job steps when the corresponding job is deleted --- migrations/000036_job_steps_fkey.down.sql | 19 +++++++++++++++++++ migrations/000036_job_steps_fkey.up.sql | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 migrations/000036_job_steps_fkey.down.sql create mode 100644 migrations/000036_job_steps_fkey.up.sql diff --git a/migrations/000036_job_steps_fkey.down.sql b/migrations/000036_job_steps_fkey.down.sql new file mode 100644 index 0000000..d101607 --- /dev/null +++ b/migrations/000036_job_steps_fkey.down.sql @@ -0,0 +1,19 @@ +BEGIN; + +SET search_path = public, pg_catalog; + +-- +-- Remove the foreign key if it already exists. +-- +ALTER TABLE IF EXISTS job_steps + DROP CONSTRAINT job_steps_job_id_fkey; + +-- +-- Add the foreign key back to the table without the cascade. +-- +ALTER TABLE IF EXISTS job_steps + ADD CONSTRAINT job_steps_job_id_fkey + FOREIGN KEY (job_id) + REFERENCES jobs (id); + +COMMIT; diff --git a/migrations/000036_job_steps_fkey.up.sql b/migrations/000036_job_steps_fkey.up.sql new file mode 100644 index 0000000..fbd875e --- /dev/null +++ b/migrations/000036_job_steps_fkey.up.sql @@ -0,0 +1,19 @@ +BEGIN; + +SET search_path = public, pg_catalog; + +-- +-- Remove the foreign key if it already exists. +-- +ALTER TABLE IF EXISTS job_steps +DROP CONSTRAINT job_steps_job_id_fkey; + +-- +-- Add the foreign key back to the table with the cascade. +-- +ALTER TABLE IF EXISTS job_steps +ADD CONSTRAINT job_steps_job_id_fkey +FOREIGN KEY (job_id) +REFERENCES jobs (id) ON DELETE CASCADE; + +COMMIT;