Skip to content

Commit

Permalink
Lazy migrate sipity entity with work
Browse files Browse the repository at this point in the history
When lazy migration is used, the sipity entity cannot be found for works
which are not yet migrated. Valkyrie resources have a `proxy_for_global_id`
with the format:
`gid://hyku/Hyrax::ValkyrieGlobalIdProxy/2f6da5dd-9314-421f-b0dd-fda84fec9ee3`
while prior works used the model name such as:
`gid://hyku/GenericWork/2f6da5dd-9314-421f-b0dd-fda84fec9ee3`.

This commit introduces a lazy migration of the sipity entity via a job
which is submitted after a work is migrated to valkyrie via the Freyja
persister.

Prior work in pull request samvera/hyku#2471
added some overrides in Hyku to resolve the sipity entity issues. These
changes still needs to be backported.

The prior work includes these changes:
The MigrateResourceService introduced a migration of the entity along
with the work's migration. This service is needed for direct migration
calls, but is not adequate for lazy migration, as the Freyja persister
does not call it for the work itself that was just migrated.

Hyku overrides to sipity.rb support cases where the entity is not yet migrated
and lazy migration is in use. This is necessary because the solr_document
is used to find the Sipity::Entity. Due to the model mapping found in the
solr document, the Entity method searches for the entity with the model
name. This is problematic when the entity is not yet migrated and the
entity is searched with a GenericWorkResource model rather than the
model.
  • Loading branch information
LaRita Robinson committed Mar 6, 2025
1 parent d4b8f81 commit c76132f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/jobs/migrate_sipity_entity_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# migrates a resource's sipity entity so it can be found
class MigrateSipityEntityJob < ApplicationJob
# input [String] id of a migrated resource
def perform(id:)
resource = Hyrax.query_service.find_by(id: id)
new_gid = Hyrax::GlobalID(resource).to_s
work = resource.internal_resource.constantize.find(id)
original_gid = Hyrax::GlobalID(work).to_s
return if new_gid == original_gid
original_entity = Sipity::Entity.find_by(proxy_for_global_id: original_gid)
original_entity.update(proxy_for_global_id: new_gid)
end
end
1 change: 1 addition & 0 deletions lib/freyja/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def convert_and_migrate_resource(orm_object)
if new_resource.is_a?(Hyrax::Work)
member_ids = new_resource.member_ids.map(&:to_s)
MigrateResourcesJob.perform_later(ids: member_ids) unless member_ids.empty?
MigrateSipityEntityJob.perform_later(id: new_resource.id)
end
end
new_resource
Expand Down

0 comments on commit c76132f

Please sign in to comment.