mirror of
https://github.com/discourse/discourse.git
synced 2024-12-30 08:53:54 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
25 lines
865 B
Ruby
25 lines
865 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AddUrlToOptimizedImages < ActiveRecord::Migration[4.2]
|
|
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
|