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)
--- /dev/null
+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