enable thumbnailing on S3

- added url to optimized image model
- refactored s3_store & local_store
This commit is contained in:
Régis Hanol
2013-07-31 23:26:34 +02:00
parent 36b6b8d78e
commit ed9417fa3b
23 changed files with 522 additions and 478 deletions

View File

@@ -0,0 +1,22 @@
class AddUrlToOptimizedImages < ActiveRecord::Migration
def up
# add a nullable url column
add_column :optimized_images, :url, :string
# compute the url for existing images
execute "UPDATE optimized_images
SET url = substring(u.url from '^\/uploads\/[^/]+\/')
|| '_optimized/'
|| substring(oi.sha1 for 3) || '/'
|| substring(oi.sha1 from 4 for 3) || '/'
|| substring(oi.sha1 from 7 for 11) || oi.extension
FROM optimized_images oi
JOIN uploads u ON u.id = oi.upload_id
WHERE optimized_images.id = oi.id;"
# change the column to be non nullable
change_column :optimized_images, :url, :string, null: false
end
def down
remove_column :optimized_images, :url
end
end