Cascade delete inheriting services
What does this MR do?
It changes the foreign key in services.inherit_id to ON DELETE CASCADE
Why
We recently introduced instance and group level integrations. An integration added to a group or instance, will create a new services
record on each project in the group/instance and inherit_from_id
points to the parent level integration. But currently there is no way to delete this top level integration. If we allow deletion we have to make sure that all inheriting integrations are deleted too. With ON DELETE CASCADE
the database can take care of cleaning up inheriting integrations.
Related issues
Database Migration
up
> bundle exec rails db:migrate
== 20201119162801 ChangeServicesInheritFromIdForeignKey: migrating ============
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:services)
-> 0.0033s
-- execute("ALTER TABLE services\nADD CONSTRAINT fk_services_inherit_from_id\nFOREIGN KEY (inherit_from_id)\nREFERENCES services (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0020s
-- execute("SET statement_timeout TO 0")
-> 0.0001s
-- execute("ALTER TABLE services VALIDATE CONSTRAINT fk_services_inherit_from_id;")
-> 0.0017s
-- execute("RESET ALL")
-> 0.0002s
-- foreign_keys(:services)
-> 0.0027s
== 20201119162801 ChangeServicesInheritFromIdForeignKey: migrated (0.0164s) ===
down
> bundle exec rails db:rollback STEP=1
== 20201119162801 ChangeServicesInheritFromIdForeignKey: reverting ============
-- foreign_keys(:services)
-> 0.0033s
-- remove_foreign_key(:services, {:name=>"fk_services_inherit_from_id"})
-> 0.0027s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:services)
-> 0.0020s
-- execute("ALTER TABLE services\nADD CONSTRAINT fk_868a8e7ad6\nFOREIGN KEY (inherit_from_id)\nREFERENCES services (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0008s
-- execute("ALTER TABLE services VALIDATE CONSTRAINT fk_868a8e7ad6;")
-> 0.0011s
== 20201119162801 ChangeServicesInheritFromIdForeignKey: reverted (0.0118s) ===
Does this MR meet the acceptance criteria?
Conformity
Edited by Andy Schoenen