Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For every importer / record combo there should be exactly one entry #921

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading