Class: Gitlab::BackgroundMigration::RemoveProjectGroupLinkWithMissingGroups

Inherits:
BatchedMigrationJob
  • Object
show all
Defined in:
lib/gitlab/background_migration/remove_project_group_link_with_missing_groups.rb

Overview

A job to remove ‘project_group_links` records whose associated group does not exist in `namespaces` table anymore.

Constant Summary

Constants inherited from BatchedMigrationJob

BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#performObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/background_migration/remove_project_group_link_with_missing_groups.rb', line 12

def perform
  each_sub_batch do |sub_batch|
    records = sub_batch.joins(
      "LEFT OUTER JOIN namespaces ON namespaces.id = project_group_links.group_id AND namespaces.type = 'Group'"
    ).where(namespaces: { id: nil })

    ids = records.map(&:id)

    next if ids.empty?

    Gitlab::AppLogger.info({ message: 'Removing project group link with non-existent groups',
                            deleted_count: ids.count,
                            ids:  ids })

    records.delete_all
  end
end