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

remove_invalid_deploy_access_level_groups.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0a107a136b0756710d7c01da0acd5ebec35703ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # This class removes invalid `protected_environment_deploy_access_levels.group_id` records.
    class RemoveInvalidDeployAccessLevelGroups < BatchedMigrationJob
      operation_name :remove_invalid_deploy_access_level_groups
      feature_category :database

      scope_to ->(relation) do
        relation.joins('INNER JOIN namespaces ON namespaces.id = protected_environment_deploy_access_levels.group_id')
                .where.not(protected_environment_deploy_access_levels: { group_id: nil })
                .where("namespaces.type = 'User'")
      end

      def perform
        each_sub_batch(&:delete_all)
      end
    end
  end
end