summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220831132802_delete_approval_rules_for_vulnerability.rb
blob: b29678f18263c23ca32978594f5d5ab4283b5a68 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

class DeleteApprovalRulesForVulnerability < Gitlab::Database::Migration[2.0]
  restrict_gitlab_migration gitlab_schema: :gitlab_main
  disable_ddl_transaction!

  BATCH_SIZE = 500
  MAX_BATCH_SIZE = 1_000
  SUB_BATCH_SIZE = 10
  MIGRATION = 'DeleteApprovalRulesWithVulnerability'
  INTERVAL = 2.minutes

  def up
    return unless Gitlab.ee?

    queue_batched_background_migration(
      MIGRATION,
      :approval_project_rules,
      :id,
      job_interval: INTERVAL,
      batch_size: BATCH_SIZE,
      max_batch_size: MAX_BATCH_SIZE,
      sub_batch_size: SUB_BATCH_SIZE
    )

    queue_batched_background_migration(
      MIGRATION,
      :approval_merge_request_rules,
      :id,
      job_interval: INTERVAL,
      batch_size: BATCH_SIZE,
      max_batch_size: MAX_BATCH_SIZE,
      sub_batch_size: SUB_BATCH_SIZE
    )
  end

  def down
    # the data deleted is related to a feature removed in 15.0: https://gitlab.com/gitlab-org/gitlab/-/issues/357300
    delete_batched_background_migration(MIGRATION, :approval_project_rules, :id, [])
    delete_batched_background_migration(MIGRATION, :approval_merge_request_rules, :id, [])
  end
end