mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 14:43:38 +08:00
25 lines
580 B
Ruby
25 lines
580 B
Ruby
|
class AddPostImageIndexes < ActiveRecord::Migration[5.2]
|
||
|
def change
|
||
|
|
||
|
%w{
|
||
|
large_images
|
||
|
broken_images
|
||
|
downloaded_images
|
||
|
}.each do |field|
|
||
|
|
||
|
execute <<~SQL
|
||
|
DELETE FROM post_custom_fields f
|
||
|
WHERE name = '#{field}' AND id > (
|
||
|
SELECT MIN(f2.id) FROM post_custom_fields f2
|
||
|
WHERE f2.post_id = f.post_id AND f2.name = f.name
|
||
|
)
|
||
|
SQL
|
||
|
|
||
|
add_index :post_custom_fields, [:post_id],
|
||
|
name: "post_custom_field_#{field}_idx",
|
||
|
unique: true,
|
||
|
where: "name = '#{field}'"
|
||
|
end
|
||
|
end
|
||
|
end
|