diff --git a/db/migrate/20220330160747_copy_site_settings_uploads_to_upload_references.rb b/db/migrate/20220330160747_copy_site_settings_uploads_to_upload_references.rb index 28fa3cabf8f..be16548f3fe 100644 --- a/db/migrate/20220330160747_copy_site_settings_uploads_to_upload_references.rb +++ b/db/migrate/20220330160747_copy_site_settings_uploads_to_upload_references.rb @@ -4,9 +4,13 @@ class CopySiteSettingsUploadsToUploadReferences < ActiveRecord::Migration[6.1] def up execute <<~SQL WITH site_settings_uploads AS ( - SELECT id, unnest(string_to_array(value, '|'))::integer upload_id - FROM site_settings - WHERE data_type = 17 + SELECT id, raw_upload_id::integer AS upload_id + FROM ( + SELECT id, unnest(string_to_array(value, '|')) AS raw_upload_id + FROM site_settings + WHERE data_type = 17 + ) raw + WHERE raw_upload_id ~ '^\d+$' UNION SELECT id, value::integer FROM site_settings