From 1536cc6de9439304222b6c66df8b9911bca1484b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:08:18 -0800 Subject: [PATCH 1/6] Switch from paperclip to kt-paperclip --- Gemfile | 2 +- Gemfile.lock | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index f39b2081d..e3f7a4db3 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem 'aws-sdk-s3' gem 'filesize' # Image processing -gem 'paperclip' # TODO: we want to migrate off this game to ActiveStorage +gem 'kt-paperclip' # TODO: we want to migrate off this game to ActiveStorage gem 'rmagick' gem 'image_processing' gem 'active_storage_validations' diff --git a/Gemfile.lock b/Gemfile.lock index 800ff1ebe..2ca8bf85c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1427,6 +1427,12 @@ GEM rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) + kt-paperclip (7.2.1) + activemodel (>= 4.2.0) + activesupport (>= 4.2.0) + marcel (~> 1.0.1) + mime-types + terrapin (~> 0.6.0) language_filter (0.3.01) libv8-node (16.10.0.0) libv8-node (16.10.0.0-x86_64-linux) @@ -1454,9 +1460,6 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2021.0704) - mimemagic (0.3.10) - nokogiri (~> 1) - rake mini_magick (4.11.0) mini_mime (1.1.2) mini_portile2 (2.8.1) @@ -1487,12 +1490,6 @@ GEM opus-ruby (1.0.1) ffi orm_adapter (0.5.0) - paperclip (6.1.0) - activemodel (>= 4.2.0) - activesupport (>= 4.2.0) - mime-types - mimemagic (~> 0.3.0) - terrapin (~> 0.6.0) paranoia (2.6.1) activerecord (>= 5.1, < 7.1) paypal-checkout-sdk (1.0.4) @@ -1718,6 +1715,7 @@ DEPENDENCIES htmlentities ibm_watson image_processing + kt-paperclip language_filter listen material_icons @@ -1727,7 +1725,6 @@ DEPENDENCIES mini_racer (~> 0.6.3) newrelic_rpm onebox! - paperclip paranoia paypal-checkout-sdk paypal_client From 329935ba0f68c94fc7b4f34c481c5b41a8774ba1 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:08:31 -0800 Subject: [PATCH 2/6] Remove old, unused field from paperclip --- app/models/page_types/location.rb | 4 ---- db/migrate/20140713043535_create_models.rb | 3 --- 2 files changed, 7 deletions(-) diff --git a/app/models/page_types/location.rb b/app/models/page_types/location.rb index b01ab1865..00410e5d8 100644 --- a/app/models/page_types/location.rb +++ b/app/models/page_types/location.rb @@ -9,10 +9,6 @@ class Location < ApplicationRecord acts_as_paranoid - # todo: clear these -- not used anymore - has_attached_file :map, styles: { original: '1920x1080>', thumb: '200x200>' } - validates_attachment_content_type :map, content_type: %r{\Aimage\/.*\Z} - validates :name, presence: true belongs_to :user diff --git a/db/migrate/20140713043535_create_models.rb b/db/migrate/20140713043535_create_models.rb index 4df7df1da..50a404a25 100644 --- a/db/migrate/20140713043535_create_models.rb +++ b/db/migrate/20140713043535_create_models.rb @@ -97,9 +97,6 @@ def change t.string :type_of t.text :description - # Map - t.attachment :map - # Culture t.string :population t.string :language From a6447fbd2e162834394aee2db332c3ef62e2e0a8 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:08:47 -0800 Subject: [PATCH 3/6] Refactor migration helper that errors on the latest rails --- db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb b/db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb index f6fbb554b..b0278e464 100644 --- a/db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb +++ b/db/migrate/20180110200009_upgrade_thredded_v0_14_to_v0_15.rb @@ -84,8 +84,8 @@ def change # rubocop:disable Metrics/MethodLength private def remove_string_limit(table, column, type: :text, indices: []) - indices.each { |(_, options)| remove_index table, name: options[:name] } + indices.each { |(index_args, options)| remove_index table, name: options[:name] } change_column table, column, type, limit: nil - indices.each { |args| add_index table, *args } + indices.each { |(index_args, options)| add_index table, index_args, **options } end end From 939ef9336058d435bde93ea380a0bb754df0ee54 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:15:32 -0800 Subject: [PATCH 4/6] move acts_as_paranoid deleted_at fields to way earlier in db migration progress --- ...930063614_upgrade_thredded_v0_15_to_v0_16.rb | 17 +++++++++++++++++ ..._deleted_at_date_times_to_thredded_tables.rb | 14 -------------- 2 files changed, 17 insertions(+), 14 deletions(-) delete mode 100644 db/migrate/20210308072329_add_deleted_at_date_times_to_thredded_tables.rb diff --git a/db/migrate/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb b/db/migrate/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb index 7d9255e80..7a3971682 100644 --- a/db/migrate/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb +++ b/db/migrate/20180930063614_upgrade_thredded_v0_15_to_v0_16.rb @@ -4,6 +4,23 @@ class UpgradeThreddedV015ToV016 < Thredded::BaseMigration def up + # Add the deleted_at column and index if they don't already exist + unless column_exists?(:thredded_topics, :deleted_at) + add_column :thredded_topics, :deleted_at, :datetime + add_index :thredded_topics, :deleted_at + + add_index :thredded_topics, [:deleted_at, :messageboard_id] + add_index :thredded_topics, [:deleted_at, :user_id] + end + + unless column_exists?(:thredded_posts, :deleted_at) + add_column :thredded_posts, :deleted_at, :datetime + add_index :thredded_posts, :deleted_at + add_index :thredded_posts, [:deleted_at, :messageboard_id] + add_index :thredded_posts, [:deleted_at, :postable_id] + add_index :thredded_posts, [:deleted_at, :user_id] + end + %i[thredded_user_topic_read_states thredded_user_private_topic_read_states].each do |table_name| add_column table_name, :unread_posts_count, :integer, default: 0, null: false add_column table_name, :read_posts_count, :integer, default: 0, null: false diff --git a/db/migrate/20210308072329_add_deleted_at_date_times_to_thredded_tables.rb b/db/migrate/20210308072329_add_deleted_at_date_times_to_thredded_tables.rb deleted file mode 100644 index b6a900979..000000000 --- a/db/migrate/20210308072329_add_deleted_at_date_times_to_thredded_tables.rb +++ /dev/null @@ -1,14 +0,0 @@ -class AddDeletedAtDateTimesToThreddedTables < ActiveRecord::Migration[6.0] - def change - add_column :thredded_topics, :deleted_at, :datetime - add_index :thredded_topics, :deleted_at - add_index :thredded_topics, [:deleted_at, :messageboard_id] - add_index :thredded_topics, [:deleted_at, :user_id] - - add_column :thredded_posts, :deleted_at, :datetime - add_index :thredded_posts, :deleted_at - add_index :thredded_posts, [:deleted_at, :messageboard_id] - add_index :thredded_posts, [:deleted_at, :postable_id] - add_index :thredded_posts, [:deleted_at, :user_id] - end -end From b9a100f66a4b4539a8e3aedb6ca00625a1a6a84d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:15:42 -0800 Subject: [PATCH 5/6] new schema --- db/schema.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 504221717..d840158eb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -215,7 +215,7 @@ create_table "basil_feedbacks", force: :cascade do |t| t.integer "basil_commission_id", null: false t.integer "user_id", null: false - t.integer "score_adjustment" + t.integer "score_adjustment", default: 0 t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["basil_commission_id"], name: "index_basil_feedbacks_on_basil_commission_id" @@ -1941,10 +1941,6 @@ t.string "name", null: false t.string "type_of" t.text "description" - t.string "map_file_name" - t.string "map_content_type" - t.integer "map_file_size" - t.datetime "map_updated_at" t.string "population" t.string "language" t.string "currency" @@ -3255,14 +3251,9 @@ t.integer "moderation_state", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.datetime "deleted_at" + t.index "\"id\", \"deleted_at\"", name: "index_thredded_posts_on_id_and_deleted_at" t.index ["created_at", "postable_id"], name: "index_thredded_posts_on_created_at_and_postable_id" t.index ["created_at"], name: "index_thredded_posts_on_created_at" - t.index ["deleted_at", "messageboard_id"], name: "index_thredded_posts_on_deleted_at_and_messageboard_id" - t.index ["deleted_at", "postable_id"], name: "index_thredded_posts_on_deleted_at_and_postable_id" - t.index ["deleted_at", "user_id"], name: "index_thredded_posts_on_deleted_at_and_user_id" - t.index ["deleted_at"], name: "index_thredded_posts_on_deleted_at" - t.index ["id", "deleted_at"], name: "index_thredded_posts_on_id_and_deleted_at" t.index ["messageboard_id"], name: "index_thredded_posts_on_messageboard_id" t.index ["moderation_state", "updated_at"], name: "index_thredded_posts_for_display" t.index ["postable_id"], name: "index_thredded_posts_on_postable_id" @@ -3325,8 +3316,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "deleted_at" - t.index ["deleted_at", "messageboard_id"], name: "index_thredded_topics_on_deleted_at_and_messageboard_id" - t.index ["deleted_at", "user_id"], name: "index_thredded_topics_on_deleted_at_and_user_id" t.index ["deleted_at"], name: "index_thredded_topics_on_deleted_at" t.index ["hash_id"], name: "index_thredded_topics_on_hash_id" t.index ["last_post_at"], name: "index_thredded_topics_on_last_post_at" From 9b910ad365667740edcb045c9cf210d5c0c45f1f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 17 Jan 2024 20:27:03 -0800 Subject: [PATCH 6/6] final schema format --- db/schema.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index d840158eb..f20bb0a83 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -3251,9 +3251,14 @@ t.integer "moderation_state", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index "\"id\", \"deleted_at\"", name: "index_thredded_posts_on_id_and_deleted_at" + t.datetime "deleted_at" t.index ["created_at", "postable_id"], name: "index_thredded_posts_on_created_at_and_postable_id" t.index ["created_at"], name: "index_thredded_posts_on_created_at" + t.index ["deleted_at", "messageboard_id"], name: "index_thredded_posts_on_deleted_at_and_messageboard_id" + t.index ["deleted_at", "postable_id"], name: "index_thredded_posts_on_deleted_at_and_postable_id" + t.index ["deleted_at", "user_id"], name: "index_thredded_posts_on_deleted_at_and_user_id" + t.index ["deleted_at"], name: "index_thredded_posts_on_deleted_at" + t.index ["id", "deleted_at"], name: "index_thredded_posts_on_id_and_deleted_at" t.index ["messageboard_id"], name: "index_thredded_posts_on_messageboard_id" t.index ["moderation_state", "updated_at"], name: "index_thredded_posts_for_display" t.index ["postable_id"], name: "index_thredded_posts_on_postable_id" @@ -3316,6 +3321,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "deleted_at" + t.index ["deleted_at", "messageboard_id"], name: "index_thredded_topics_on_deleted_at_and_messageboard_id" + t.index ["deleted_at", "user_id"], name: "index_thredded_topics_on_deleted_at_and_user_id" t.index ["deleted_at"], name: "index_thredded_topics_on_deleted_at" t.index ["hash_id"], name: "index_thredded_topics_on_hash_id" t.index ["last_post_at"], name: "index_thredded_topics_on_last_post_at"