2022-10-11 01:57:18 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
class DestroyInvalidGroupMembers < Gitlab::BackgroundMigration::BatchedMigrationJob # rubocop:disable Style/Documentation
|
|
|
|
scope_to ->(relation) do
|
|
|
|
relation.where(source_type: 'Namespace')
|
|
|
|
.joins('LEFT OUTER JOIN namespaces ON members.source_id = namespaces.id')
|
|
|
|
.where(namespaces: { id: nil })
|
|
|
|
end
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
operation_name :delete_all
|
2023-03-17 16:20:25 +05:30
|
|
|
feature_category :database
|
2023-01-13 00:05:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def perform
|
2023-01-13 00:05:48 +05:30
|
|
|
each_sub_batch do |sub_batch|
|
2022-10-11 01:57:18 +05:30
|
|
|
invalid_ids = sub_batch.map(&:id)
|
|
|
|
Gitlab::AppLogger.info({ message: 'Removing invalid group member records',
|
|
|
|
deleted_count: invalid_ids.size, ids: invalid_ids })
|
|
|
|
|
|
|
|
sub_batch.delete_all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|