Resolve "Inconsistent schema - indexes"
What does this MR do and why?
In this MR, we are fixing the index_approval_rules_code_owners_rule_type
index.
In our structure.sql file, the index seems fine, but the index in our production database is not correct.
structure.sql:
index_approval_rules_code_owners_rule_type btree (merge_request_id) WHERE (rule_type = 2);
production db:
index_approval_rules_code_owners_rule_type btree (merge_request_id, rule_type) WHERE rule_type = 2
Please take a look here to know more about this issue.
up:
== 20220128155814 FixApprovalRulesCodeOwnersRuleTypeIndex: migrating ==========
-- indexes(:approval_merge_request_rules)
-> 0.0029s
-- rename_index(:approval_merge_request_rules, "index_approval_rules_code_owners_rule_type", "index_approval_rules_code_owners_rule_type_old")
-> 0.0009s
-- transaction_open?()
-> 0.0000s
-- index_exists?(:approval_merge_request_rules, :merge_request_id, {:where=>"rule_type = 2", :name=>"index_approval_rules_code_owners_rule_type", :algorithm=>:concurrently})
-> 0.0028s
-- add_index(:approval_merge_request_rules, :merge_request_id, {:where=>"rule_type = 2", :name=>"index_approval_rules_code_owners_rule_type", :algorithm=>:concurrently})
-> 0.0021s
-- transaction_open?()
-> 0.0000s
-- indexes(:approval_merge_request_rules)
-> 0.0076s
-- remove_index(:approval_merge_request_rules, {:algorithm=>:concurrently, :name=>"index_approval_rules_code_owners_rule_type_old"})
-> 0.0016s
== 20220128155814 FixApprovalRulesCodeOwnersRuleTypeIndex: migrated (0.0214s) =
down:
== 20220128155814 FixApprovalRulesCodeOwnersRuleTypeIndex: reverting ==========
-- transaction_open?()
-> 0.0000s
-- indexes(:approval_merge_request_rules)
-> 0.0055s
-- execute("SET statement_timeout TO 0")
-> 0.0005s
-- remove_index(:approval_merge_request_rules, {:algorithm=>:concurrently, :name=>"index_approval_rules_code_owners_rule_type"})
-> 0.0021s
-- execute("RESET statement_timeout")
-> 0.0007s
== 20220128155814 FixApprovalRulesCodeOwnersRuleTypeIndex: reverted (0.0110s) =
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #349549 (closed)
Edited by Diogo Frazão