Last active
August 29, 2015 14:06
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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