Welcome to mirror list, hosted at ThFree Co, Russian Federation.

database_helpers.rb « import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e73c3afe9bd7efbf4c6705541d79dcbdfc41cd7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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.
      # relation - An ActiveRecord::Relation to use for finding the table name
      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 = Gitlab::Database.main # rubocop:disable Gitlab/BulkInsert
                 .bulk_insert(relation.table_name, [attributes], return_ids: true)

        result.first
      end
    end
  end
end