FIX: Handle duplicates in hotlinked_media migration (#16611)
In the old custom_field-based system, it was possible for a url to be both 'downloaded' and 'broken'. The new table enforces uniqueness, so we need to drop invalid data.
This commit is contained in:
parent
96e7c85177
commit
bebb4fd111
@ -60,6 +60,7 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
|
||||
FROM post_custom_fields pcf
|
||||
JOIN json_array_elements_text(pcf.value::json) url ON true
|
||||
WHERE name='broken_images'
|
||||
ON CONFLICT (post_id, md5(url::text)) DO NOTHING
|
||||
SQL
|
||||
|
||||
execute <<~SQL
|
||||
@ -74,6 +75,7 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
|
||||
FROM post_custom_fields pcf
|
||||
JOIN json_array_elements_text(pcf.value::json) url ON true
|
||||
WHERE name='large_images'
|
||||
ON CONFLICT (post_id, md5(url::text)) DO NOTHING
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user