Skip to content

Commit

Permalink
Rake task for updating collection_type_gid
Browse files Browse the repository at this point in the history
The structure of the stored collection type gid changed in Hyrax 3.0

A rake task is needed to update the collection_type_gid that is stored
on the collection as part of the upgrade from Hyrax 2.x process. This
references the logic from the rake task that Hyrax has in versons 3 & 4,
and updates it to work within Hyku tenants.

The definition of collection_type_gid= changed in Hyrax 5.0. This
rake task is known to work for updates to versions prior to Hyrax 5.
Functionality for later versions is unknown.
  • Loading branch information
laritakr committed Mar 6, 2024
1 parent cc71d30 commit bc9beda
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/tasks/collection_type_global_id.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true
namespace :hyrax do
namespace :collections do
desc 'Update CollectionType global id references for Hyrax 3.0.0'
# Note: the definition of collection_type_gid= changed in Hyrax 5.0. This
# rake task is known to work for updates to versions prior to Hyrax 5.
# Use for later versions is unknown.
task update_collection_type_global_ids: :environment do
Account.find_each do |account|
next if account.search_only.eql? true

puts "🎪🎪 Updating collection -> collection type GlobalId references within '#{account.name}' tenant"
AccountElevator.switch!(account.cname)

count = 0

Collection.find_each do |collection|
next if collection.collection_type_gid == collection.collection_type.to_global_id.to_s

collection.public_send(:collection_type_gid=, collection.collection_type.to_global_id, force: true)

collection.save &&
count += 1
end

puts "💯💯 Updated #{count} collections within '#{account.name}' tenant"
end
end
end
end

0 comments on commit bc9beda

Please sign in to comment.