summaryrefslogtreecommitdiff
path: root/db/migrate/20210324112439_add_index_mirror_data_on_retry_next_execution_where_status.rb
blob: 68ce5363b7088b42fc14e6781ce76ad39aa6e730 (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
# frozen_string_literal: true

# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class AddIndexMirrorDataOnRetryNextExecutionWhereStatus < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  INDEX_NAME = 'index_mirror_data_non_scheduled_or_started'

  disable_ddl_transaction!

  def up
    add_concurrent_index :project_mirror_data,
      [:next_execution_timestamp, :retry_count],
      where: "(status)::text <> ALL ('{scheduled,started}'::text[])",
      name: INDEX_NAME
  end

  def down
    remove_concurrent_index :project_mirror_data,
      [:next_execution_timestamp, :retry_count],
      where: "(status)::text <> ALL ('{scheduled,started}'::text[])",
      name: INDEX_NAME
  end
end