Class: Gitlab::BackgroundMigration::BackfillProjectNamespaceDetails

Inherits:
BatchedMigrationJob show all
Defined in:
lib/gitlab/background_migration/backfill_project_namespace_details.rb

Constant Summary

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY, Gitlab::BackgroundMigration::BatchedMigrationJob::MINIMUM_PAUSE_MS

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, cursor, cursor?, cursor_columns, feature_category, #filter_batch, generic_instance, health_context_tables, #initialize, job_arguments, job_arguments_count, operation_name, scope_to, tables_to_check_for_vacuum

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



9
10
11
12
13
# File 'lib/gitlab/background_migration/backfill_project_namespace_details.rb', line 9

def perform
  each_sub_batch do |sub_batch|
    upsert_project_namespace_details(sub_batch)
  end
end

#upsert_project_namespace_details(relation) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/background_migration/backfill_project_namespace_details.rb', line 15

def upsert_project_namespace_details(relation)
  connection.execute(
    "    INSERT INTO namespace_details (description, description_html, cached_markdown_version, created_at, updated_at, namespace_id)\n      SELECT projects.description, projects.description_html, projects.cached_markdown_version, now(), now(), projects.project_namespace_id\n      FROM projects\n      WHERE projects.id IN(\#{relation.select(:id).to_sql})\n        AND projects.project_namespace_id IS NOT NULL\n    ON CONFLICT (namespace_id) DO UPDATE SET\n      description = EXCLUDED.description,\n      description_html = EXCLUDED.description_html,\n      cached_markdown_version = EXCLUDED.cached_markdown_version,\n      updated_at = EXCLUDED.updated_at;\n    SQL\n  )\nend\n"