From bebb4fd11181f3deb277b2e4cb0e7148b61fb71d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 3 May 2022 17:17:27 +0100 Subject: [PATCH] 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. --- db/migrate/20220428094026_create_post_hotlinked_media.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20220428094026_create_post_hotlinked_media.rb b/db/migrate/20220428094026_create_post_hotlinked_media.rb index cc86831045..b34e363725 100644 --- a/db/migrate/20220428094026_create_post_hotlinked_media.rb +++ b/db/migrate/20220428094026_create_post_hotlinked_media.rb @@ -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