Commit cb34b114 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add unique index merge_request_approval_rules.name

This adds a unique index to [merge_request_id, name] for
merge_request_approval_rules. This makes sure that the users cannot
create the the same approval rule based on a codeowner pattern twice.
parent b19dfcbc
......@@ -233,6 +233,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do
t.integer "approvals_required", limit: 2, default: 0, null: false
t.boolean "code_owner", default: false, null: false
t.string "name", null: false
t.index ["merge_request_id", "code_owner", "name"], name: "approval_rule_name_index_for_code_owners", unique: true, where: "(code_owner = true)", using: :btree
t.index ["merge_request_id", "code_owner"], name: "index_approval_merge_request_rules_1", using: :btree
end
......
# frozen_string_literal: true
class AddIndexToNameOnApprovalMergeRequestRules < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
INDEX_NAME = 'approval_rule_name_index_for_code_owners'
def up
add_concurrent_index(
:approval_merge_request_rules,
[:merge_request_id, :code_owner, :name],
unique: true,
where: "code_owner = 't'",
name: INDEX_NAME
)
end
def down
remove_concurrent_index(
:approval_merge_request_rules,
[:merge_request_id, :name],
name: INDEX_NAME
)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment