2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Import
|
|
|
|
module DatabaseHelpers
|
|
|
|
# Inserts a raw row and returns the ID of the inserted row.
|
|
|
|
#
|
|
|
|
# attributes - The attributes/columns to set.
|
2019-10-12 21:52:04 +05:30
|
|
|
# relation - An ActiveRecord::Relation to use for finding the table name
|
2018-11-20 20:47:30 +05:30
|
|
|
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.
|
2021-10-27 15:23:28 +05:30
|
|
|
result = Gitlab::Database.main # rubocop:disable Gitlab/BulkInsert
|
2018-11-20 20:47:30 +05:30
|
|
|
.bulk_insert(relation.table_name, [attributes], return_ids: true)
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
result.first
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|