Ensure package files are removed when project is destroyed
What does this MR do and why?
When you delete a project, the package files are not removed. This bug was adressed in !77325 (closed), but the MR was blocked by a "refactoring around package/package files removal". Now, the refactoring is completed and this MR replaces the previous MR to solve this problem as suggested in !77325 (comment 834017801).
Solves #288834
/cc @bufferoverflow
How to set up and validate locally
See #288834
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
💾 Database review
⤴ Migration up
$ r db:migrate
== 20220207153403 UpdatePackagesPackagesProjectForeignKey: migrating ==========
-- change_column_null(:packages_packages, :project_id, true)
-> 0.0254s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_packages)
-> 0.0046s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE packages_packages\nADD CONSTRAINT fk_packages_project_id\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0140s
-- execute("SET statement_timeout TO 0")
-> 0.0013s
-- execute("ALTER TABLE packages_packages VALIDATE CONSTRAINT fk_packages_project_id;")
-> 0.0132s
-- execute("RESET statement_timeout")
-> 0.0015s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_packages)
-> 0.0321s
-- remove_foreign_key(:packages_packages, {:column=>:project_id, :on_delete=>:cascade, :name=>"fk_rails_e1ac527425"})
-> 0.0168s
== 20220207153403 UpdatePackagesPackagesProjectForeignKey: migrated (0.2224s) =
== 20220221094819 AddIndexOnPackagesIdWhenNullProjectId: migrating ============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:packages_packages, :id, {:name=>"index_packages_on_id_when_null_project_id", :where=>"status != 4 AND project_id IS NULL", :algorithm=>:concurrently})
-> 0.0213s
-- add_index(:packages_packages, :id, {:name=>"index_packages_on_id_when_null_project_id", :where=>"status != 4 AND project_id IS NULL", :algorithm=>:concurrently})
-> 0.0725s
== 20220221094819 AddIndexOnPackagesIdWhenNullProjectId: migrated (0.1059s) ===
⤵ Migration down
$ r db:migrate:down VERSION=20220221094819
== 20220221094819 AddIndexOnPackagesIdWhenNullProjectId: reverting ============
-- transaction_open?()
-> 0.0000s
-- indexes(:packages_packages)
-> 0.0124s
-- execute("SET statement_timeout TO 0")
-> 0.0015s
-- remove_index(:packages_packages, {:algorithm=>:concurrently, :name=>"index_packages_on_id_when_null_project_id"})
-> 0.0195s
-- execute("RESET statement_timeout")
-> 0.0011s
== 20220221094819 AddIndexOnPackagesIdWhenNullProjectId: reverted (0.0397s) ===
$ r db:migrate:down VERSION=20220207153403
== 20220207153403 UpdatePackagesPackagesProjectForeignKey: reverting ==========
-- current_schema()
-> 0.0006s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0006s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE packages_packages\nADD CONSTRAINT check_e7fcb13b2c\nCHECK ( project_id IS NOT NULL )\nNOT VALID;\n")
-> 0.0034s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_packages)
-> 0.0045s
-- transaction_open?()
-> 0.0000s
-- execute("ALTER TABLE packages_packages\nADD CONSTRAINT fk_rails_e1ac527425\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
-> 0.0044s
-- execute("SET statement_timeout TO 0")
-> 0.0014s
-- execute("ALTER TABLE packages_packages VALIDATE CONSTRAINT fk_rails_e1ac527425;")
-> 0.0093s
-- execute("RESET statement_timeout")
-> 0.0012s
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:packages_packages)
-> 0.0045s
-- remove_foreign_key(:packages_packages, {:column=>:project_id, :on_delete=>:nullify, :name=>"fk_packages_project_id"})
-> 0.0080s
== 20220207153403 UpdatePackagesPackagesProjectForeignKey: reverted (0.0912s) =
🔬 Queries
Edited by Jonas Wälter