summaryrefslogtreecommitdiff
path: root/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb
blob: 23c94a809d4d3c95698d824186d76a15371c76d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class RemoveTemporaryCiBuildsIndex < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

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

  # To use create/remove index concurrently
  disable_ddl_transaction!

  def up
    return unless index_exists?(:ci_builds, :id, name: 'index_for_ci_builds_retried_migration')

    remove_concurrent_index(:ci_builds, :id, name: "index_for_ci_builds_retried_migration")
  end

  def down
    # this was a temporary index for a migration that was never
    # present previously so this probably shouldn't be here but it's
    # easier to test the drop if we have a way to create it.
    add_concurrent_index("ci_builds", ["id"],
                         name: "index_for_ci_builds_retried_migration",
                         where: "(retried IS NULL)",
                         using: :btree)
  end
end