Skip to content

Commit

Permalink
For every importer / record combo there should be exactly one entry (#…
Browse files Browse the repository at this point in the history
…921)

* for every importer record combo there should be an entry. no longer reuse entries from previous importers

* entry identifier is no longer unique and needs a scoped index
  • Loading branch information
orangewolf authored Feb 10, 2024
1 parent 8763b9a commit 06bde07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/parsers/bulkrax/application_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,15 @@ def new_entry(entryclass, type)
end

def find_or_create_entry(entryclass, identifier, type, raw_metadata = nil)
entry = entryclass.where(
# limit entry search to just this importer or exporter. Don't go moving them
entry = importerexporter.entries.where(
identifier: identifier
).first
entry ||= entryclass.new(
importerexporter_id: importerexporter.id,
importerexporter_type: type,
identifier: identifier
).first_or_create!
)
entry.raw_metadata = raw_metadata
entry.save!
entry
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20240209070952_update_identifier_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UpdateIdentifierIndex < ActiveRecord::Migration[5.2]
def change
remove_index :bulkrax_entries, :identifier if index_exists?(:bulkrax_entries, :identifier )
add_index :bulkrax_entries, [:identifier, :importerexporter_id, :importerexporter_type], name: 'bulkrax_identifier_idx' unless index_exists?(:bulkrax_entries, [:identifier, :importerexporter_id, :importerexporter_type], name: 'bulkrax_identifier_idx')
end
end
4 changes: 2 additions & 2 deletions spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_02_08_005801) do
ActiveRecord::Schema.define(version: 2024_02_09_070952) do

create_table "accounts", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -42,7 +42,7 @@
t.string "importerexporter_type", default: "Bulkrax::Importer"
t.integer "import_attempts", default: 0
t.string "status_message", default: "Pending"
t.index ["identifier"], name: "index_bulkrax_entries_on_identifier"
t.index ["identifier", "importerexporter_id", "importerexporter_type"], name: "bulkrax_identifier_idx"
t.index ["importerexporter_id", "importerexporter_type"], name: "bulkrax_entries_importerexporter_idx"
t.index ["type"], name: "index_bulkrax_entries_on_type"
end
Expand Down

0 comments on commit 06bde07

Please sign in to comment.