-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix on delete cascade in
rule_type_data_sources
. (#5085)
This migration recreates the foreign key constraint to delete rows from `rule_type_data_sources` when a record is deleted from `rule_type`. Note that it is safe to just drop and recreate the constraint as the previous version prevented the deletion of rule types if they referenced a data source, so it was not possible to have dangling records.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
database/migrations/000110_rule_rtype_data_sources_cascading_delete.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- SPDX-FileCopyrightText: Copyright 2024 The Minder Authors | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
BEGIN; | ||
|
||
ALTER TABLE rule_type_data_sources | ||
DROP CONSTRAINT rule_type_data_sources_rule_type_id_fkey; | ||
|
||
ALTER TABLE rule_type_data_sources | ||
ADD CONSTRAINT rule_type_data_sources_rule_type_id_fkey | ||
FOREIGN KEY (rule_type_id) REFERENCES rule_type(id); | ||
|
||
COMMIT; |
30 changes: 30 additions & 0 deletions
30
database/migrations/000110_rule_rtype_data_sources_cascading_delete.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- SPDX-FileCopyrightText: Copyright 2024 The Minder Authors | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
BEGIN; | ||
|
||
-- Generally speaking, given two projects R (root) and A within the | ||
-- same hierarchy, a rule type defined in project A can reference a | ||
-- data source defined in project R, and in such cases we want to | ||
-- prevent admins of project R from deleting the data source without | ||
-- fixing said rule type in project A (or having someone else fix it | ||
-- for them), but we still want admins from project A to be able to | ||
-- delete their rule types without hindrance. | ||
-- | ||
-- This migration recreates the foreign key constraint to delete rows | ||
-- from `rule_type_data_sources` when a record is deleted from | ||
-- `rule_type`. | ||
-- | ||
-- Note that it is safe to just drop and recreate the constraint as | ||
-- the previous version prevented the deletion of rule types if they | ||
-- referenced a data source, so it was not possible to have dangling | ||
-- records. | ||
|
||
ALTER TABLE rule_type_data_sources | ||
DROP CONSTRAINT rule_type_data_sources_rule_type_id_fkey; | ||
|
||
ALTER TABLE rule_type_data_sources | ||
ADD CONSTRAINT rule_type_data_sources_rule_type_id_fkey | ||
FOREIGN KEY (rule_type_id) REFERENCES rule_type(id) ON DELETE CASCADE; | ||
|
||
COMMIT; |