Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20200416111111_migrate_vulnerability_dismissals.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ec8b991968b3e97b52a2de2e355ffdda525342a (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
# frozen_string_literal: true

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

  DOWNTIME = false

  disable_ddl_transaction!

  MIGRATION = 'UpdateVulnerabilitiesToDismissed'.freeze
  BATCH_SIZE = 500
  DELAY_INTERVAL = 2.minutes.to_i

  class Vulnerability < ActiveRecord::Base
    self.table_name = 'vulnerabilities'
    self.inheritance_column = :_type_disabled

    include ::EachBatch
  end

  def up
    return unless Gitlab.ee?

    Vulnerability.select('project_id').group(:project_id).each_batch(of: BATCH_SIZE, column: "project_id") do |project_batch, index|
      batch_delay = (index - 1) * BATCH_SIZE * DELAY_INTERVAL

      project_batch.each_with_index do |project, project_batch_index|
        project_delay = project_batch_index * DELAY_INTERVAL
        migrate_in(batch_delay + project_delay, MIGRATION, project[:project_id])
      end
    end
  end

  def down
    # nothing to do
  end
end