Add issues.correct_work_item_type FK
What does this MR do and why?
The issues.correct_work_item_type column has been backfilled and the BBM
finalized. We should now be able to add a VALID
FK on the column.
We tried to follow the documented path to add the FK but due to a quirk with postgres transactions and INVALID FKs we had to drop it and backfill before adding the FK as discussed in gitlab-com/gl-infra/production#18692 (comment 2153334226) (internal only).
Migration output
UP
main: == [advisory_lock_connection] object_id: 129880, pg_backend_pid: 96641
main: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: migrating =================
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute("ALTER TABLE issues ADD CONSTRAINT fk_1adaba52b0 FOREIGN KEY (correct_work_item_type_id) REFERENCES work_item_types (correct_id) NOT VALID;")
main: -> 0.0027s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0003s
main: -- execute("ALTER TABLE issues VALIDATE CONSTRAINT fk_1adaba52b0;")
main: -> 0.0083s
main: -- execute("RESET statement_timeout")
main: -> 0.0005s
main: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: migrated (0.0766s) ========
main: == [advisory_lock_connection] object_id: 129880, pg_backend_pid: 96641
ci: == [advisory_lock_connection] object_id: 130260, pg_backend_pid: 96643
ci: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: migrating =================
ci: -- transaction_open?(nil)
ci: -> 0.0000s
ci: -- transaction_open?(nil)
ci: -> 0.0000s
ci: -- execute("ALTER TABLE issues ADD CONSTRAINT fk_1adaba52b0 FOREIGN KEY (correct_work_item_type_id) REFERENCES work_item_types (correct_id) NOT VALID;")
ci: -> 0.0026s
ci: -- execute("SET statement_timeout TO 0")
ci: -> 0.0003s
ci: -- execute("ALTER TABLE issues VALIDATE CONSTRAINT fk_1adaba52b0;")
ci: -> 0.0071s
ci: -- execute("RESET statement_timeout")
ci: -> 0.0004s
ci: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: migrated (0.0486s) ========
ci: == [advisory_lock_connection] object_id: 130260, pg_backend_pid: 96643
DOWN
main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 95898
main: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: reverting =================
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- remove_foreign_key(:issues, {:column=>:correct_work_item_type_id})
main: -> 0.0036s
main: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: reverted (0.0701s) ========
main: == [advisory_lock_connection] object_id: 129500, pg_backend_pid: 95898
ci: == [advisory_lock_connection] object_id: 138720, pg_backend_pid: 96151
ci: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: reverting =================
ci: -- transaction_open?(nil)
ci: -> 0.0000s
ci: -- remove_foreign_key(:issues, {:column=>:correct_work_item_type_id})
ci: -> 0.0032s
ci: == 20241111204547 AddIssuesCorrectWorkItemTypeIdFk: reverted (0.0321s) ========
ci: == [advisory_lock_connection] object_id: 138720, pg_backend_pid: 96151
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #503662 (closed)
Edited by Mario Celi