Skip to content

A platform for community discussion. Free, open, simple.

DEV: remove unused columns from posts and topics

Sam Saffron310a7edee591
diff --git a/app/models/post.rb b/app/models/post.rb
index acc6c540f2e..5da5d163200 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -10,6 +10,9 @@ class Post < ActiveRecord::Base
include HasCustomFields
include LimitedEdit
+ # remove line Jan 2021
+ self.ignored_columns = ["avg_time"]
+
cattr_accessor :plugin_permitted_create_params
self.plugin_permitted_create_params = {}
@@ -1107,7 +1110,6 @@ end
# like_count :integer default(0), not null
# incoming_link_count :integer default(0), not null
# bookmark_count :integer default(0), not null
-# avg_time :integer
# score :float
# reads :integer default(0), not null
# post_type :integer default(1), not null
diff --git a/app/models/topic.rb b/app/models/topic.rb
index f1f17443cef..dbc6c44d155 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -10,6 +10,9 @@ class Topic < ActiveRecord::Base
include LimitedEdit
extend Forwardable
+ # remove line Jan 2021
+ self.ignored_columns = ["avg_time"]
+
def_delegator :featured_users, :user_ids, :featured_user_ids
def_delegator :featured_users, :choose, :feature_topic_users
@@ -1567,7 +1570,6 @@ end
# featured_user1_id :integer
# featured_user2_id :integer
# featured_user3_id :integer
-# avg_time :integer
# deleted_at :datetime
# highest_post_number :integer default(0), not null
# image_url :string
diff --git a/db/post_migrate/20200430010528_remove_avg_time_from_topics_posts.rb b/db/post_migrate/20200430010528_remove_avg_time_from_topics_posts.rb
new file mode 100644
index 00000000000..848f9e569f7
--- /dev/null
+++ b/db/post_migrate/20200430010528_remove_avg_time_from_topics_posts.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class RemoveAvgTimeFromTopicsPosts < ActiveRecord::Migration[6.0]
+ disable_ddl_transaction!
+
+ def up
+ # this makes it re-runnable and also works if it was not created initially
+ execute <<~SQL
+ ALTER TABLE topics DROP COLUMN IF EXISTS avg_time CASCADE
+ SQL
+
+ execute <<~SQL
+ ALTER TABLE posts DROP COLUMN IF EXISTS avg_time CASCADE
+ SQL
+ end
+
+ def down
+ # do nothing re-runnable
+ end
+end