Skip to content

Nullify project_namespace_id reference

Jan Provaznik requested to merge jprovazn-project_fk into master

What does this MR do and why?

It's possible we will have to rollback project namespace backfilling migration (so delete project namespaces), we need to avoid cascade deletion of linked projects.

Related to #348981 (closed) Pre-requisite for !73640 (merged)

migration output

== 20220112090556 RemoveCascadeDeleteFromProjectNamespaceForeignKey: migrating 
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:projects)
   -> 0.0024s
-- remove_foreign_key(:projects, {:column=>:project_namespace_id})
   -> 0.0030s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:projects)
   -> 0.0017s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE projects\nADD CONSTRAINT fk_71625606ac\nFOREIGN KEY (project_namespace_id)\nREFERENCES namespaces (id)\nON DELETE SET NULL\nNOT VALID;\n")
   -> 0.0013s
-- execute("SET statement_timeout TO 0")
   -> 0.0004s
-- execute("ALTER TABLE projects VALIDATE CONSTRAINT fk_71625606ac;")
   -> 0.0033s
-- execute("RESET statement_timeout")
   -> 0.0004s
== 20220112090556 RemoveCascadeDeleteFromProjectNamespaceForeignKey: migrated (0.0356s) 

rollback:
== 20220112090556 RemoveCascadeDeleteFromProjectNamespaceForeignKey: reverting 
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:projects)
   -> 0.0021s
-- remove_foreign_key(:projects, {:column=>:project_namespace_id})
   -> 0.0029s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:projects)
   -> 0.0017s
-- transaction_open?()
   -> 0.0000s
-- execute("ALTER TABLE projects\nADD CONSTRAINT fk_71625606ac\nFOREIGN KEY (project_namespace_id)\nREFERENCES namespaces (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.0014s
-- execute("SET statement_timeout TO 0")
   -> 0.0004s
-- execute("ALTER TABLE projects VALIDATE CONSTRAINT fk_71625606ac;")
   -> 0.0062s
-- execute("RESET statement_timeout")
   -> 0.0004s
== 20220112090556 RemoveCascadeDeleteFromProjectNamespaceForeignKey: reverted (0.0286s) 

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jan Provaznik

Merge request reports

Loading