Last active
August 29, 2015 14:16
-
-
Save palkan/a81679d004737df87fed to your computer and use it in GitHub Desktop.
"Restore" S3 assets after updating Paperclip hash_data
This file contains 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
# Suppose we updated our hash_data for Paperclip | |
OLD_HASH = ":class/:attachment/:id/:style" | |
NEW_HASH = ":class/:attachment/:id/:style/:updated_at" | |
ACL = :public_read | |
def restore(r) | |
return unless r.file.exists? | |
new_key = r.file.path[1..-1] | |
r.file.options[:hash_data] = OLD_HASH; | |
old_key = r.file.path[1..-1] | |
o = bucket.objects[old_key]; | |
if o.exists? | |
o.move_to(new_key, acl: ACL) | |
else | |
p "Doesn't exist: #{old_key}" | |
end | |
r.file.options[:hash_data] = NEW_HASH; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment