2022-11-25 23:54:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
# Backfill namespace_details for a range of namespaces
|
|
|
|
class BackfillNamespaceDetails < ::Gitlab::BackgroundMigration::BatchedMigrationJob
|
2023-01-13 00:05:48 +05:30
|
|
|
operation_name :backfill_namespace_details
|
2023-03-17 16:20:25 +05:30
|
|
|
feature_category :database
|
2023-01-13 00:05:48 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def perform
|
2023-01-13 00:05:48 +05:30
|
|
|
each_sub_batch do |sub_batch|
|
2022-11-25 23:54:43 +05:30
|
|
|
upsert_namespace_details(sub_batch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def upsert_namespace_details(relation)
|
|
|
|
connection.execute(
|
|
|
|
<<~SQL
|
|
|
|
INSERT INTO namespace_details (description, description_html, cached_markdown_version, created_at, updated_at, namespace_id)
|
|
|
|
SELECT namespaces.description, namespaces.description_html, namespaces.cached_markdown_version, now(), now(), namespaces.id
|
|
|
|
FROM namespaces
|
|
|
|
WHERE namespaces.id IN(#{relation.select(:id).to_sql})
|
|
|
|
AND namespaces.type <> 'Project'
|
|
|
|
ON CONFLICT (namespace_id) DO NOTHING;
|
|
|
|
SQL
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|