Method: Gitlab::GithubImport::BulkImporting#build_database_rows

Defined in:
lib/gitlab/github_import/bulk_importing.rb

#build_database_rows(enum) ⇒ Object

Builds and returns an Array of objects to bulk insert into the database and array of validation errors if object is invalid.

enum - An Enumerable that returns the objects to turn into database

rows.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab/github_import/bulk_importing.rb', line 21

def build_database_rows(enum)
  errors = []
  rows = enum.each_with_object([]) do |(object, _), result|
    next if already_imported?(object)

    attrs = build_attributes(object)
    build_record = model.new(attrs)

    if build_record.invalid?
      github_identifiers = github_identifiers(object)

      log_error(github_identifiers, build_record.errors.full_messages)
      errors << {
        validation_errors: build_record.errors,
        external_identifiers: github_identifiers
      }
      next
    end

    result << attrs
  end

  log_and_increment_counter(rows.size, :fetched)

  [rows, errors]
end