Add a rake task to migrate trace data to ActiveStorage
This commit is contained in:
parent
0410596908
commit
b244905cd2
2 changed files with 29 additions and 0 deletions
|
@ -300,6 +300,26 @@ class Trace < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def migrate_to_storage!
|
||||
file.attach(:io => File.open(trace_name),
|
||||
:filename => name,
|
||||
:content_type => content_type(trace_name),
|
||||
:identify => false)
|
||||
|
||||
if inserted
|
||||
image.attach(:io => File.open(large_picture_name),
|
||||
:filename => "#{id}.gif",
|
||||
:content_type => "image/gif")
|
||||
icon.attach(:io => File.open(icon_picture_name),
|
||||
:filename => "#{id}_icon.gif",
|
||||
:content_type => "image/gif")
|
||||
end
|
||||
|
||||
save!
|
||||
|
||||
remove_files
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def content_type(file)
|
||||
|
|
9
lib/tasks/migrate_traces_to_storage.rake
Normal file
9
lib/tasks/migrate_traces_to_storage.rake
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace :traces do
|
||||
desc "Migrate trace files to ActiveStorage"
|
||||
task :migrate_to_storage => :environment do
|
||||
Trace
|
||||
.with_attached_file
|
||||
.where(:file_attachment => { :id => nil })
|
||||
.find_each(&:migrate_to_storage!)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue