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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/background_migration/destroy_invalid_group_members.rb')
-rw-r--r--lib/gitlab/background_migration/destroy_invalid_group_members.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/destroy_invalid_group_members.rb b/lib/gitlab/background_migration/destroy_invalid_group_members.rb
new file mode 100644
index 00000000000..35ac42f76ab
--- /dev/null
+++ b/lib/gitlab/background_migration/destroy_invalid_group_members.rb
@@ -0,0 +1,23 @@
+# 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
+
+ def perform
+ each_sub_batch(operation_name: :delete_all) do |sub_batch|
+ 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