summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/backfill_project_namespace_details.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/background_migration/backfill_project_namespace_details.rb')
-rw-r--r--lib/gitlab/background_migration/backfill_project_namespace_details.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/backfill_project_namespace_details.rb b/lib/gitlab/background_migration/backfill_project_namespace_details.rb
new file mode 100644
index 00000000000..9bee3cf21e8
--- /dev/null
+++ b/lib/gitlab/background_migration/backfill_project_namespace_details.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+module Gitlab
+ module BackgroundMigration
+ # Backfill project namespace_details for a range of projects
+ class BackfillProjectNamespaceDetails < ::Gitlab::BackgroundMigration::BatchedMigrationJob
+ operation_name :backfill_project_namespace_details
+
+ def perform
+ each_sub_batch do |sub_batch|
+ upsert_project_namespace_details(sub_batch)
+ end
+ end
+
+ def upsert_project_namespace_details(relation)
+ connection.execute(
+ <<~SQL
+ INSERT INTO namespace_details (description, description_html, cached_markdown_version, created_at, updated_at, namespace_id)
+ SELECT projects.description, projects.description_html, projects.cached_markdown_version, now(), now(), projects.project_namespace_id
+ FROM projects
+ WHERE projects.id IN(#{relation.select(:id).to_sql})
+ ON CONFLICT (namespace_id) DO NOTHING;
+ SQL
+ )
+ end
+ end
+ end
+end