2018-08-13 22:36:15 +00:00
|
|
|
# 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-06-13 13:12:28 +00:00
|
|
|
# relation - An ActiveRecord::Relation to use for finding the table name
|
2018-08-13 22:36:15 +00:00
|
|
|
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-11-15 15:10:57 +00:00
|
|
|
result = ApplicationRecord # rubocop:disable Gitlab/BulkInsert
|
|
|
|
.legacy_bulk_insert(relation.table_name, [attributes], return_ids: true)
|
2018-08-13 22:36:15 +00:00
|
|
|
|
2019-06-13 13:12:28 +00:00
|
|
|
result.first
|
2018-08-13 22:36:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|