Skip to content

Instantly share code, notes, and snippets.

@ryaz
Last active August 29, 2015 14:04
Show Gist options
  • Save ryaz/b5087991c9e73a39ca24 to your computer and use it in GitHub Desktop.
Save ryaz/b5087991c9e73a39ca24 to your computer and use it in GitHub Desktop.
migrate_from_file_storage_to_s3
namespace :paperclip_migration do
desc "migrate files from file storage to s3"
task :migrate_to_s3 => :environment do
puts "Migrating... carrierwave..."
Asset1.find_each do |record|
path = record.avatar.path.to_s
if path != record.avatar.default_url
file_path = (Rails.root.join('public', path)
if File.exists?(file_path)
file = File.open(file_path)
puts "Saving file: #{file_path} to Amazon S3..."
record.avatar = file
record.save!
else
puts "Can't find file: #{file_path}..."
end
end
end
puts "paperclip..."
Asset2.find_each do |record|
if filename = record.avatar_file_name
file_path = Rails.root.join("public/system/avatars/#{c.id}/original/#{filename}")
if File.exists?(file_path)
file = File.open(file_path)
puts "Saving file: #{file_path} to Amazon S3..."
record.avatar = file
record.save!
else
puts "Can't find file: #{file_path}..."
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment