Skip to content

Instantly share code, notes, and snippets.

@davidray
Last active August 29, 2015 14:06
Show Gist options
  • Save davidray/c3948a27ab2aa2cf0a9d to your computer and use it in GitHub Desktop.
Save davidray/c3948a27ab2aa2cf0a9d to your computer and use it in GitHub Desktop.
This is what you do after you casually upgrade paperclip from v2.x to v4.x and w/o noticing the default paths changed…
s3 = AWS::S3.new
bucket = s3.buckets['trooptrack-prod']
no_doc = []
done_it = []
Event.where('attachment_file_name is not null').
find_each do |thing|
old_key = "attachments/#{thing.id}/original/#{thing.attachment_file_name}"
new_key = thing.attachment.path
new_key[0] = ''
begin
obj = bucket.objects[old_key]
obj.copy_to(new_key)
done_it << thing.id
rescue AWS::S3::Errors::NoSuchKey
no_doc << thing.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment