Change terraform_states.locked_by_user_id foreign key to SET NULL
What does this MR do?
Fixes an edge case where a user could not be deleted if they
held a lock (in the Terraform sense, not a database lock) on a
Terraform state, as it would violate the foreign key constraint.
Migrations
== 20210305002016 UpdateTerraformStatesLockedByUserIdForeignKey: reverting ====
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:terraform_states)
-> 0.0035s
-- execute("ALTER TABLE terraform_states\nADD CONSTRAINT fk_rails_558901b030\nFOREIGN KEY (locked_by_user_id)\nREFERENCES users (id)\n\nNOT VALID;\n")
-> 0.0041s
-- execute("SET statement_timeout TO 0")
-> 0.0008s
-- execute("ALTER TABLE terraform_states VALIDATE CONSTRAINT fk_rails_558901b030;")
-> 0.0052s
-- execute("RESET ALL")
-> 0.0008s
-- remove_foreign_key(:terraform_states, :users, {:name=>"fk_558901b030"})
-> 0.0047s
== 20210305002016 UpdateTerraformStatesLockedByUserIdForeignKey: reverted (0.0339s)
== 20210305002016 UpdateTerraformStatesLockedByUserIdForeignKey: migrating ====
-- transaction_open?()
-> 0.0000s
-- foreign_keys(:terraform_states)
-> 0.0040s
-- execute("ALTER TABLE terraform_states\nADD CONSTRAINT fk_558901b030\nFOREIGN KEY (locked_by_user_id)\nREFERENCES users (id)\nON DELETE SET NULL\nNOT VALID;\n")
-> 0.0022s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- execute("ALTER TABLE terraform_states VALIDATE CONSTRAINT fk_558901b030;")
-> 0.0035s
-- execute("RESET ALL")
-> 0.0010s
-- remove_foreign_key(:terraform_states, :users, {:name=>"fk_rails_558901b030"})
-> 0.0038s
== 20210305002016 UpdateTerraformStatesLockedByUserIdForeignKey: migrated (0.0246s)
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
- [-] Documentation (if required)
- [-] Code review guidelines
-
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Edited by Tiger Watson