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

reset_shared_runners_for_transferred_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: 0053cafb4aca748585dcead1a337f52349144601 (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
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Resets inconsistent state of shared_runners_enabled for projects that have been transferred
    class ResetSharedRunnersForTransferredProjects
      # Model specifically used for migration.
      class Namespace < ActiveRecord::Base
        include EachBatch

        self.table_name = 'namespaces'
      end

      # Model specifically used for migration.
      class Project < ActiveRecord::Base
        self.table_name = 'projects'
      end

      def perform(start_id, stop_id)
        Project.reset_column_information

        Namespace.where(id: start_id..stop_id).each_batch(of: 1_000) do |relation|
          ids = relation.where(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: false).select(:id)

          Project.where(namespace_id: ids).update_all(shared_runners_enabled: false)
        end
      end
    end
  end
end