Module: Gitlab::Import::DatabaseHelpers

Included in:
GithubImport::Importer::IssueImporter, MergeRequestCreator, MergeRequestHelpers, JiraImport::ImportIssueWorker
Defined in:
lib/gitlab/import/database_helpers.rb

Instance Method Summary collapse

Instance Method Details

#insert_and_return_id(attributes, relation) ⇒ Object

Inserts a raw row and returns the ID of the inserted row.

attributes - The attributes/columns to set. relation - An ActiveRecord::Relation to use for finding the table name



10
11
12
13
14
15
16
17
18
# File 'lib/gitlab/import/database_helpers.rb', line 10

def insert_and_return_id(attributes, relation)
  # We use bulk_insert here so we can bypass any queries executed by
  # callbacks or validation rules, as doing this wouldn't scale when
  # importing very large projects.
  result = ApplicationRecord # rubocop:disable Gitlab/BulkInsert
           .legacy_bulk_insert(relation.table_name, [attributes], return_ids: true)

  result.first
end