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

backfill_push_rules_id_in_projects.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b9ef70424a76b47071eb69c674265467c9f8aef (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
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Class that will insert record into project_push_rules
    # for each existing push_rule
    class BackfillPushRulesIdInProjects
      # Temporary AR table for push rules
      class ProjectSetting < ActiveRecord::Base
        self.table_name = 'project_settings'
      end

      def perform(start_id, stop_id)
        ProjectSetting.connection.execute(<<~SQL)
          UPDATE project_settings ps1
          SET push_rule_id = pr.id
          FROM project_settings ps2
          INNER JOIN push_rules pr
          ON ps2.project_id = pr.project_id
          WHERE pr.is_sample = false
          AND pr.id BETWEEN #{start_id} AND #{stop_id}
          AND ps1.project_id = ps2.project_id
        SQL
      end
    end
  end
end