2017-08-31 00:06:56 -04:00
|
|
|
class FixOptimizedImagesUrls < ActiveRecord::Migration[4.2]
|
2013-08-28 15:29:45 -04:00
|
|
|
def up
|
|
|
|
# `AddUrlToOptimizedImages` was wrongly computing the URLs. This fixes it!
|
|
|
|
execute "UPDATE optimized_images
|
2013-08-28 17:21:46 -04:00
|
|
|
SET url = substring(oi.url from '^\\/uploads\\/[^/]+\\/_optimized\\/[0-9a-f]{3}\\/[0-9a-f]{3}\\/[0-9a-f]{11}')
|
2013-08-28 15:29:45 -04:00
|
|
|
|| '_'
|
|
|
|
|| oi.width
|
|
|
|
|| 'x'
|
|
|
|
|| oi.height
|
2013-08-28 17:21:46 -04:00
|
|
|
|| substring(oi.url from '\\.\\w{3,4}$')
|
2013-08-28 15:29:45 -04:00
|
|
|
FROM optimized_images oi
|
|
|
|
WHERE optimized_images.id = oi.id
|
2013-08-28 17:21:46 -04:00
|
|
|
AND oi.url ~ '^\\/uploads\\/[^/]+\\/_optimized\\/[0-9a-f]{3}\\/[0-9a-f]{3}\\/[0-9a-f]{11}\\.';"
|
2013-08-28 15:29:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
raise ActiveRecord::IrreversibleMigration
|
|
|
|
end
|
|
|
|
end
|