-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4847 from sul-dlss/t4825-release_tag_report
Adds release tags report.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# Reports most recent release tags. | ||
|
||
# Invoke via: | ||
# bin/rails r -e production "LatestReleaseTags.report" | ||
class LatestReleaseTags | ||
SQL = <<~SQL.squish.freeze | ||
select tags.*, case when dros.id is not null then 'dro' else 'collection' end as object_type from | ||
( | ||
select distinct on (druid, released_to, what) | ||
druid, released_to, what, release | ||
from release_tags | ||
order by druid, released_to, what, created_at desc | ||
) as tags | ||
left outer join dros on tags.druid=dros.external_identifier; | ||
SQL | ||
|
||
def self.report | ||
puts "druid,released_to,what,release,object_type\n" | ||
|
||
sql_result_rows = ActiveRecord::Base.connection.execute(SQL) | ||
sql_result_rows.each do |row| | ||
puts "#{row['druid']},#{row['released_to']},#{row['what']},#{row['release']},#{row['object_type']}" | ||
end | ||
end | ||
end |