summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180619121030_enqueue_delete_diff_files_workers.rb
blob: c4d2f5f61a0ac0986aaa71e96bd1543f6fa1529e (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
class EnqueueDeleteDiffFilesWorkers < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  SCHEDULER = 'ScheduleDiffFilesDeletion'.freeze
  TMP_INDEX = 'tmp_partial_diff_id_with_files_index'.freeze

  disable_ddl_transaction!

  def up
    unless index_exists_by_name?(:merge_request_diffs, TMP_INDEX)
      add_concurrent_index(:merge_request_diffs, :id, where: "(state NOT IN ('without_files', 'empty'))", name: TMP_INDEX)
    end

    BackgroundMigrationWorker.perform_async(SCHEDULER)

    # We don't remove the index since it's going to be used on DeleteDiffFiles
    # worker. We should remove it in an upcoming release.
  end

  def down
    if index_exists_by_name?(:merge_request_diffs, TMP_INDEX)
      remove_concurrent_index_by_name(:merge_request_diffs, TMP_INDEX)
    end
  end
end