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

backfill_ci_runner_semver.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0901649f7895e27e1d55683a30819ae669b247e8 (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

module Gitlab
  module BackgroundMigration
    # A job to update semver column in ci_runners in batches based on existing version values
    class BackfillCiRunnerSemver < Gitlab::BackgroundMigration::BatchedMigrationJob
      def perform
        each_sub_batch(
          operation_name: :backfill_ci_runner_semver,
          batching_scope: ->(relation) { relation.where('semver::cidr IS NULL') }
        ) do |sub_batch|
          ranged_query = sub_batch.select(
            %q(id AS r_id,
               substring(ci_runners.version FROM 'v?(\d+\.\d+\.\d+)') AS extracted_semver)
          )

          update_sql = <<~SQL
            UPDATE
              ci_runners
            SET semver = extracted_semver
            FROM (#{ranged_query.to_sql}) v
            WHERE id = v.r_id
              AND v.extracted_semver IS NOT NULL
          SQL

          connection.execute(update_sql)
        end
      end
    end
  end
end