Skip to content

Draft: Prevent auto-delete of epic children

charlie ablett requested to merge 54471-cablett-epic-cascade into master

What does this MR do?

When deleting an epic, the children automatically get destroyed as well due to ON DELETE CASCADE in the foreign key. This MR changes that value to SET NULL. See https://gitlab.slack.com/archives/C72HPNV97/p1614717313122300 (internal) for context.

It also changes the UX warning so the user is clear about the consequences of deleting the epic.

!55574 (merged) should be merged first as it's the "smallest first iteration"

related to #321752 (closed)

Screenshots (strongly suggested)

before

after

Database migration outputs

up

$ bundle exec rake db:migrate:up VERSION=20210302222539
== 20210302222539 ChangeEpicParentForeignKeyCascadeSetNull: migrating =========
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:epics)
   -> 0.0022s
-- execute("ALTER TABLE epics\nADD CONSTRAINT epics_parent_fk_nullify_on_destroy\nFOREIGN KEY (parent_id)\nREFERENCES epics (id)\nON DELETE SET NULL\nNOT VALID;\n")
   -> 0.0129s
-- execute("SET statement_timeout TO 0")
   -> 0.0014s
-- execute("ALTER TABLE epics VALIDATE CONSTRAINT epics_parent_fk_nullify_on_destroy;")
   -> 0.0065s
-- execute("RESET ALL")
   -> 0.0004s
-- remove_foreign_key(:epics, {:column=>:parent_id})
   -> 0.0039s
== 20210302222539 ChangeEpicParentForeignKeyCascadeSetNull: migrated (0.0364s) 

down

$ bundle exec rake db:migrate:down VERSION=20210302222539
== 20210302222539 ChangeEpicParentForeignKeyCascadeSetNull: reverting =========
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:epics)
   -> 0.0022s
-- execute("ALTER TABLE epics\nADD CONSTRAINT fk_25b99c1be3\nFOREIGN KEY (parent_id)\nREFERENCES epics (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0010s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- execute("ALTER TABLE epics VALIDATE CONSTRAINT fk_25b99c1be3;")
   -> 0.0025s
-- execute("RESET ALL")
   -> 0.0004s
-- remove_foreign_key(:epics, {:column=>:parent_id})
   -> 0.0033s
== 20210302222539 ChangeEpicParentForeignKeyCascadeSetNull: reverted (0.0144s) 

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by charlie ablett

Merge request reports