Fix index name to Rails default to ensure idempotency

See https://gitlab.com/gitlab-com/infrastructure/issues/3822
This commit is contained in:
Stan Hu 2018-03-08 11:36:41 -08:00
parent 08c407cc0f
commit 43957e7a81

View file

@ -3,20 +3,21 @@ class AddSectionNameIdIndexOnCiBuildTraceSections < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
INDEX_NAME = 'index_ci_build_trace_sections_on_section_name_id'
disable_ddl_transaction!
def up
# MySQL may already have this as a foreign key
unless index_exists?(:ci_build_trace_sections, :section_name_id)
add_concurrent_index :ci_build_trace_sections, :section_name_id
unless index_exists?(:ci_build_trace_sections, :section_name_id, name: INDEX_NAME)
add_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
end
def down
# We cannot remove index for MySQL because it's needed for foreign key
if Gitlab::Database.postgresql?
remove_concurrent_index :ci_build_trace_sections, :section_name_id
remove_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
end
end