Class: Gitlab::BackgroundMigration::UpdateJiraTrackerDataDeploymentTypeBasedOnUrl

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

Overview

rubocop: disable Style/Documentation

Defined Under Namespace

Classes: JiraTrackerData

Constant Summary collapse

JIRA_CLOUD_REGEX =
%r{^https?://[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?\.atlassian\.net$}ix.freeze

Instance Method Summary collapse

Instance Method Details

#perform(start_id, end_id) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url.rb', line 22

def perform(start_id, end_id)
  trackers_data = JiraTrackerData
    .where(deployment_type: 'unknown')
    .where(id: start_id..end_id)

  cloud, server = trackers_data.partition { |tracker_data| tracker_data.url.match?(JIRA_CLOUD_REGEX) }

  cloud_mappings = cloud.each_with_object({}) do |tracker_data, hash|
    hash[tracker_data] = { deployment_type: 2 }
  end

  server_mapppings = server.each_with_object({}) do |tracker_data, hash|
    hash[tracker_data] = { deployment_type: 1 }
  end

  mappings = cloud_mappings.merge(server_mapppings)

  ::Gitlab::Database::BulkUpdate.execute(%i[deployment_type], mappings)
end