20171121144800_ci_pipelines_index_on_project_id_ref_status_id.rb 933 Bytes
Newer Older
1 2 3
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

4
class CiPipelinesIndexOnProjectIdRefStatusId < ActiveRecord::Migration[4.2]
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  include Gitlab::Database::MigrationHelpers

  # Set this constant to true if this migration requires downtime.
  DOWNTIME = false

  disable_ddl_transaction!

  TABLE = :ci_pipelines
  OLD_COLUMNS = %i[project_id ref status].freeze
  NEW_COLUMNS = %i[project_id ref status id].freeze

  def up
    unless index_exists?(TABLE, NEW_COLUMNS)
      add_concurrent_index(TABLE, NEW_COLUMNS)
    end

    if index_exists?(TABLE, OLD_COLUMNS)
      remove_concurrent_index(TABLE, OLD_COLUMNS)
    end
  end

  def down
    unless index_exists?(TABLE, OLD_COLUMNS)
      add_concurrent_index(TABLE, OLD_COLUMNS)
    end

    if index_exists?(TABLE, NEW_COLUMNS)
      remove_concurrent_index(TABLE, NEW_COLUMNS)
    end
  end
end