Class: Gitlab::BackgroundMigration::CopyCiBuildsColumnsToSecurityScans

Inherits:
Object
  • Object
show all
Extended by:
Utils::Override
Defined in:
lib/gitlab/background_migration/copy_ci_builds_columns_to_security_scans.rb

Constant Summary collapse

UPDATE_BATCH_SIZE =
500

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Instance Method Details

#perform(start_id, stop_id) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/background_migration/copy_ci_builds_columns_to_security_scans.rb', line 11

def perform(start_id, stop_id)
  (start_id..stop_id).step(UPDATE_BATCH_SIZE).each do |offset|
    batch_start = offset
    batch_stop = offset + UPDATE_BATCH_SIZE - 1

    ActiveRecord::Base.connection.execute <<~SQL
      UPDATE
        security_scans
      SET
        project_id = ci_builds.project_id,
        pipeline_id = ci_builds.commit_id
      FROM ci_builds
      WHERE ci_builds.type='Ci::Build' 
        AND ci_builds.id=security_scans.build_id 
        AND security_scans.id BETWEEN #{Integer(batch_start)} AND #{Integer(batch_stop)}
    SQL
  end

  mark_job_as_succeeded(start_id, stop_id)
rescue StandardError => error
  Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error)
end