2022-06-21 17:19:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
# Backfill group_features for an array of groups
|
2022-07-16 23:28:13 +05:30
|
|
|
class BackfillGroupFeatures < ::Gitlab::BackgroundMigration::BatchedMigrationJob
|
2022-08-27 11:52:29 +05:30
|
|
|
job_arguments :batch_size
|
2023-01-13 00:05:48 +05:30
|
|
|
operation_name :upsert_group_features
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
def perform
|
2022-07-16 23:28:13 +05:30
|
|
|
each_sub_batch(
|
|
|
|
batching_arguments: { order_hint: :type },
|
|
|
|
batching_scope: ->(relation) { relation.where(type: 'Group') }
|
|
|
|
) do |sub_batch|
|
2022-08-27 11:52:29 +05:30
|
|
|
upsert_group_features(sub_batch)
|
2022-06-21 17:19:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
def upsert_group_features(relation)
|
2022-06-21 17:19:12 +05:30
|
|
|
connection.execute(
|
|
|
|
<<~SQL
|
|
|
|
INSERT INTO group_features (group_id, created_at, updated_at)
|
|
|
|
SELECT namespaces.id as group_id, now(), now()
|
|
|
|
FROM namespaces
|
|
|
|
WHERE namespaces.type = 'Group' AND namespaces.id IN(#{relation.select(:id).limit(batch_size).to_sql})
|
|
|
|
ON CONFLICT (group_id) DO NOTHING;
|
|
|
|
SQL
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|