-
Notifications
You must be signed in to change notification settings - Fork 7
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 #7990 from ministryofjustice/CTSKF-1002
CTSKF-1002 - CCCD - Task to copy message attachment (singular) to attachments (plural)
- Loading branch information
Showing
3 changed files
with
36 additions
and
2 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
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,26 @@ | ||
namespace :documents do | ||
desc 'Copy all message attachment to message attachments.' | ||
task :duplicate_message_attachment => :environment do | ||
messages = Message.all | ||
puts "There are #{messages.count} messages." | ||
|
||
messages.each do |message| | ||
if message.attachment.attached? | ||
puts "Duplicating attachment of message ##{message.id}." | ||
attachment_blob = message.attachment.blob | ||
|
||
message.attachments.attach(attachment_blob) | ||
puts "Attachment #{attachment_blob.filename} is duplicated in the database." | ||
else | ||
puts "There is no attachment in message ##{message.id}." | ||
end | ||
end | ||
puts "duplicate_message_attachment done!" | ||
end | ||
|
||
desc'Count blob map.' | ||
task :count_blob_map => :environment do | ||
blobs = ActiveStorage::Attachment.includes(:blob, blob: :attachments).where(name: 'attachment').map(&:blob) | ||
puts blobs.map { |blob| blob.attachments.count }.tally | ||
end | ||
end |
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