FIX: Skip invalid custom_field json in hotlinked_media migration (#16630)

Truly testing for JSON validity would require defining a new postgres function. Checking just the first character should take care of all the cases of invalid historic data that we've seen.
This commit is contained in:
David Taylor 2022-05-04 15:05:18 +01:00 committed by GitHub
parent 62ed7d4968
commit db9ae32e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,7 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
JOIN json_each_text(pcf.value::json) obj ON true JOIN json_each_text(pcf.value::json) obj ON true
JOIN uploads ON obj.value::bigint = uploads.id JOIN uploads ON obj.value::bigint = uploads.id
WHERE name='downloaded_images' WHERE name='downloaded_images'
AND pcf.value LIKE '{%' -- JSON Object
ON CONFLICT (post_id, md5(url::text)) DO NOTHING ON CONFLICT (post_id, md5(url::text)) DO NOTHING
SQL SQL
@ -61,6 +62,7 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
FROM post_custom_fields pcf FROM post_custom_fields pcf
JOIN json_array_elements_text(pcf.value::json) url ON true JOIN json_array_elements_text(pcf.value::json) url ON true
WHERE name='broken_images' WHERE name='broken_images'
AND pcf.value LIKE '[%' -- JSON Array
ON CONFLICT (post_id, md5(url::text)) DO NOTHING ON CONFLICT (post_id, md5(url::text)) DO NOTHING
SQL SQL
@ -76,6 +78,7 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
FROM post_custom_fields pcf FROM post_custom_fields pcf
JOIN json_array_elements_text(pcf.value::json) url ON true JOIN json_array_elements_text(pcf.value::json) url ON true
WHERE name='large_images' WHERE name='large_images'
AND pcf.value LIKE '[%' -- JSON Array
ON CONFLICT (post_id, md5(url::text)) DO NOTHING ON CONFLICT (post_id, md5(url::text)) DO NOTHING
SQL SQL
end end