From d8f855e375a3afd40e00658dd5c70622fcd88780 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 17 May 2024 10:50:36 -0500 Subject: [PATCH] Create a report for files with no size Ref #4990 --- app/reports/files_with_no_size.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/reports/files_with_no_size.rb diff --git a/app/reports/files_with_no_size.rb b/app/reports/files_with_no_size.rb new file mode 100644 index 000000000..aed118000 --- /dev/null +++ b/app/reports/files_with_no_size.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Look for Files that don't have a size attribute +# Invoke via: +# bin/rails r -e production "FilesWithNoSize.report" +class FilesWithNoSize + JSON_PATH = '$.contains[*].structural.contains[*]' + SQL = <<~SQL.squish.freeze + SELECT ro.external_identifier + FROM repository_objects AS ro, repository_object_versions AS rov WHERE + ro.head_version_id = rov.id + AND ro.object_type = 'dro' + AND jsonb_array_length(jsonb_path_query_array(rov.structural, '#{JSON_PATH}')) != + jsonb_array_length(jsonb_path_query_array(rov.structural, '#{JSON_PATH}.size')) + SQL + + def self.report + puts "item_druid\n" + result = ActiveRecord::Base.connection.execute(SQL) + + result.each do |row| + puts row.fetch('external_identifier') + end + end +end