To migrate the application as of April 2020: • leave models/screenshot.rb with “has_attached_file” • bundle exec rake db:migrate • bin/move_paperclip_to_activestorage • set models/screenshot.rb to “has_one_attached”
18 lines
465 B
Text
Executable file
18 lines
465 B
Text
Executable file
#!bin/rails runner
|
|
|
|
# Move images from Paperclip path to ActiveRecord path
|
|
|
|
ActiveStorage::Attachment.find_each do |attachment|
|
|
name = attachment.name
|
|
|
|
source = attachment.record.send(name).path
|
|
dest_dir = File.join(
|
|
"storage",
|
|
attachment.blob.key.first(2),
|
|
attachment.blob.key.first(4).last(2))
|
|
dest = File.join(dest_dir, attachment.blob.key)
|
|
|
|
FileUtils.mkdir_p(dest_dir)
|
|
puts "Moving #{source} to #{dest}"
|
|
FileUtils.cp(source, dest)
|
|
end
|