summaryrefslogtreecommitdiff
path: root/db/post_migrate/20201119092319_schedule_repopulate_historical_vulnerability_statistics.rb
blob: 598cc4d93d013b17632ab4f649db2d0def01d252 (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
# frozen_string_literal: true

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

  DOWNTIME = false
  BATCH_SIZE = 50
  DELAY_INTERVAL = 5.minutes
  MIGRATION_CLASS = 'PopulateVulnerabilityHistoricalStatistics'
  DAY_COUNT = 365

  disable_ddl_transaction!

  class ProjectSetting < ActiveRecord::Base
    include EachBatch

    self.table_name = 'project_settings'

    scope :has_vulnerabilities, -> { where('has_vulnerabilities IS TRUE') }
  end

  def up
    ProjectSetting.has_vulnerabilities.each_batch(of: BATCH_SIZE) do |batch, index|
      migrate_in(index * DELAY_INTERVAL, MIGRATION_CLASS, [batch.pluck(:project_id), DAY_COUNT])
    end
  end

  def down
    # no-op
  end
end