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

backfill_namespace_details.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57254c09f78d33304fd523b2280a70a7dddee6e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Backfill namespace_details for a range of namespaces
    class BackfillNamespaceDetails < ::Gitlab::BackgroundMigration::BatchedMigrationJob
      operation_name :backfill_namespace_details
      feature_category :database

      def perform
        each_sub_batch do |sub_batch|
          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