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

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

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

  INDEX_NAME = 'index_vulnerability_occurrences_on_id_and_confidence_eq_zero'
  DOWNTIME = false

  disable_ddl_transaction!
  BATCH_SIZE = 1_000
  INTERVAL = 2.minutes

  # 286_159 records to be updated on GitLab.com
  def up
    # create temporary index for undefined vulnerabilities
    add_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME)

    return unless Gitlab.ee?

    migration = Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceConfidenceLevel
    migration_name = migration.to_s.demodulize
    relation = migration::Occurrence.undefined_confidence
    queue_background_migration_jobs_by_range_at_intervals(relation,
                                                          migration_name,
                                                          INTERVAL,
                                                          batch_size: BATCH_SIZE)
  end

  def down
    # no-op
    # temporary index is to be dropped in a different migration in an upcoming release
    remove_concurrent_index(:vulnerability_occurrences, :id, where: 'confidence = 0', name: INDEX_NAME)
    # This migration can not be reversed because we can not know which records had undefined confidence
  end
end