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

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

module Gitlab
  module BackgroundMigration
    # A job to remove protected_tag_create_access_levels for groups that do not have project_group_links
    # to the project for the associated protected branch
    class DeleteInvalidProtectedTagCreateAccessLevels < BatchedMigrationJob
      operation_name :delete_invalid_protected_tag_create_access_levels
      scope_to ->(relation) { relation.where.not(group_id: nil) }
      feature_category :source_code_management

      def perform
        each_sub_batch do |sub_batch|
          sub_batch
          .joins('INNER JOIN protected_tags ON protected_tags.id = protected_tag_id')
          .joins(%(
            LEFT OUTER JOIN project_group_links pgl
              ON pgl.group_id = protected_tag_create_access_levels.group_id
              AND pgl.project_id = protected_tags.project_id
          ))
          .where(%(
            pgl.id IS NULL
          )).delete_all
        end
      end
    end
  end
end