Class: Gitlab::BackgroundMigration::BackfillEpicBasicFieldsToWorkItemRecord

Inherits:
BatchedMigrationJob
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_epic_basic_fields_to_work_item_record.rb

Direct Known Subclasses

ResyncBasicEpicFieldsToWorkItem

Defined Under Namespace

Classes: Epics, Issues, Users, WorkItemColors, WorkItemTypes

Constant Summary collapse

WORK_ITEM_TYPE_EPIC =

see WorkItems::Type::BASE_TYPES[:enum_value]

7
DEFAULT_EPIC_COLOR =

see Epic::DEFAULT_COLOR

'#1068bf'
NON_MATCHING_BASIC_FIELDS =
{ tmp_epic_id: :id, namespace_id: :group_id, relative_position: :id }.freeze
MATCHING_BASIC_FIELDS =
%i[
  author_id iid state_id title title_html description description_html cached_markdown_version lock_version
  last_edited_at last_edited_by_id created_at updated_at closed_at closed_by_id confidential
  external_key imported_from
].freeze

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

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, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gitlab/background_migration/backfill_epic_basic_fields_to_work_item_record.rb', line 46

def perform
  each_sub_batch do |sub_batch|
    # prevent an epic being updated while we sync its data to issues table. Wrap the locking into a transaction
    # so that locks are kept for the duration of transaction.
    sub_batch_with_lock = sub_batch.lock!('FOR UPDATE')
    # First update any epics with a not null issue_id and only afterwards follow-up with the epics
    # without an issue_id, otherwise we end up updating the same issues/epics twice, as first time we'd
    # fetch epics without an issue_id then set the issue_id and then we query the same batch for epics
    # with an issue_id we just did set.
    backfill_epics_with_synced_work_item(sub_batch_with_lock)
    backfill_epics_without_synced_work_item(sub_batch_with_lock)
    # force reload the batch as it now should have the issue_id set and we need it
    # to create work_item_colors records.
    backfill_epics_color(sub_batch_with_lock.all)
  end
end