Skip to content

Commit

Permalink
Add parent_id backfill rake migration
Browse files Browse the repository at this point in the history
  • Loading branch information
masaball committed Jun 14, 2024
1 parent ae2494a commit 5322a99
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/tasks/avalon_migrations.rake
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,34 @@ namespace :avalon do
puts("#{error.length} files migrated with unsupported mime types. Refer to caption_type_errors.log for full list of SupplementalFile IDs.")
end
end
desc "Backfill the parent_id field on SupplementalFile records as part of improvements to the model to allow transcript indexing"
task backfill_parent_id: :environment do
error = []
logger = Logger.new(File.join(Rails.root, 'log/parent_id_backfill_errors.log'))

objects = ActiveFedora::SolrService.get("supplemental_files_json_ssi:*", { fl: "id,supplemental_files_json_ssi", rows: 1000000 })["response"]["docs"]
objects.each do |object|
files = JSON.parse(object["supplemental_files_json_ssi"]).collect { |file_gid| GlobalID::Locator.locate(file_gid) }

files.each do |file|
begin
if file.parent_id.blank?
file.parent_id = object["id"]
file.save!
else
next
end
rescue
error += [file.id]
end
end
end

puts("Backfill complete.")
if error.present?
logger.info("Failed to save: #{error}")
puts("#{error.length} files failed to save. Refer to parent_id_backfill_errors.log for full list of SupplementalFile IDs.")
end
end
end
end

0 comments on commit 5322a99

Please sign in to comment.