Class: Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData

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

Overview

This migration takes all issue trackers and move data from properties to data field tables (jira_tracker_data and issue_tracker_data)

Defined Under Namespace

Classes: IssueTrackerData, JiraTrackerData

Instance Method Summary collapse

Instance Method Details

#perform(start_id, stop_id) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data.rb', line 47

def perform(start_id, stop_id)
  columns = 'id, properties, title, description, type'
  batch_condition = "id >= #{start_id} AND id <= #{stop_id} AND category = 'issue_tracker' \
    AND properties IS NOT NULL AND properties != '{}' AND properties != ''"

  data_subselect = "SELECT 1 \
    FROM jira_tracker_data \
    WHERE jira_tracker_data.service_id = services.id \
    UNION SELECT 1 \
    FROM issue_tracker_data \
    WHERE issue_tracker_data.service_id = services.id"

  query = "SELECT #{columns} FROM services WHERE #{batch_condition} AND NOT EXISTS (#{data_subselect})"

  migrated_ids = []
  data_to_insert(query).each do |table, data|
    service_ids = data.map { |s| s['service_id'] }

    next if service_ids.empty?

    migrated_ids += service_ids
    Gitlab::Database.bulk_insert(table, data) # rubocop:disable Gitlab/BulkInsert
  end

  return if migrated_ids.empty?

  move_title_description(migrated_ids)
end