From 991b62b6f123e9df63f443bba411eee4f3c3066a Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 12 May 2022 15:34:35 +0100 Subject: [PATCH] DEV: Drop old hotlinked image data from post_custom_fields (#16594) `20220428094026_create_post_hotlinked_media` moved this data into a dedicated table --- app/models/post.rb | 9 ------ app/models/post_custom_field.rb | 3 -- ...01_delete_hotlinked_image_custom_fields.rb | 32 +++++++++++++++++++ 3 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 db/post_migrate/20220429164301_delete_hotlinked_image_custom_fields.rb diff --git a/app/models/post.rb b/app/models/post.rb index 7ffed8307ae..d956255c9fd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -72,21 +72,12 @@ class Post < ActiveRecord::Base # We can pass several creating options to a post via attributes attr_accessor :image_sizes, :quoted_post_numbers, :no_bump, :invalidate_oneboxes, :cooking_options, :skip_unique_check, :skip_validation - LARGE_IMAGES ||= "large_images" - BROKEN_IMAGES ||= "broken_images" - DOWNLOADED_IMAGES ||= "downloaded_images" MISSING_UPLOADS ||= "missing uploads" MISSING_UPLOADS_IGNORED ||= "missing uploads ignored" NOTICE ||= "notice" SHORT_POST_CHARS ||= 1200 - # TODO: Drop the data from these three custom fields, - # drop the indexes, and remove the relavent constants - register_custom_field_type(LARGE_IMAGES, :json) - register_custom_field_type(BROKEN_IMAGES, :json) - register_custom_field_type(DOWNLOADED_IMAGES, :json) - register_custom_field_type(MISSING_UPLOADS, :json) register_custom_field_type(MISSING_UPLOADS_IGNORED, :boolean) diff --git a/app/models/post_custom_field.rb b/app/models/post_custom_field.rb index 1cfeabe4309..58c8705fd5a 100644 --- a/app/models/post_custom_field.rb +++ b/app/models/post_custom_field.rb @@ -23,7 +23,4 @@ end # index_post_custom_fields_on_post_id (post_id) UNIQUE WHERE ((name)::text = 'missing uploads'::text) # index_post_custom_fields_on_post_id_and_name (post_id,name) # index_post_id_where_missing_uploads_ignored (post_id) UNIQUE WHERE ((name)::text = 'missing uploads ignored'::text) -# post_custom_field_broken_images_idx (post_id) UNIQUE WHERE ((name)::text = 'broken_images'::text) -# post_custom_field_downloaded_images_idx (post_id) UNIQUE WHERE ((name)::text = 'downloaded_images'::text) -# post_custom_field_large_images_idx (post_id) UNIQUE WHERE ((name)::text = 'large_images'::text) # diff --git a/db/post_migrate/20220429164301_delete_hotlinked_image_custom_fields.rb b/db/post_migrate/20220429164301_delete_hotlinked_image_custom_fields.rb new file mode 100644 index 00000000000..ce2a43ece2f --- /dev/null +++ b/db/post_migrate/20220429164301_delete_hotlinked_image_custom_fields.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +class DeleteHotlinkedImageCustomFields < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def up + execute <<~SQL + DELETE FROM post_custom_fields + WHERE name IN ( + 'downloaded_images', + 'broken_images', + 'large_images' + ) + SQL + + execute <<~SQL + DROP INDEX CONCURRENTLY IF EXISTS post_custom_field_broken_images_idx + SQL + + execute <<~SQL + DROP INDEX CONCURRENTLY IF EXISTS post_custom_field_downloaded_images_idx + SQL + + execute <<~SQL + DROP INDEX CONCURRENTLY IF EXISTS post_custom_field_large_images_idx + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end