2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
class CreateTopTopics < ActiveRecord::Migration[4.2]
|
2014-01-13 19:02:14 -05:00
|
|
|
PERIODS = %i[yearly monthly weekly daily]
|
|
|
|
SORT_ORDERS = %i[posts views likes]
|
|
|
|
|
2013-12-23 18:50:36 -05:00
|
|
|
def change
|
2013-12-31 14:37:43 -05:00
|
|
|
create_table :top_topics, force: true do |t|
|
2013-12-23 18:50:36 -05:00
|
|
|
t.belongs_to :topic
|
|
|
|
|
2014-01-13 19:02:14 -05:00
|
|
|
PERIODS.each do |period|
|
|
|
|
SORT_ORDERS.each do |sort|
|
2013-12-23 18:50:36 -05:00
|
|
|
t.integer "#{period}_#{sort}_count".to_sym, null: false, default: 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_index :top_topics, :topic_id, unique: true
|
|
|
|
|
2014-01-13 19:02:14 -05:00
|
|
|
PERIODS.each do |period|
|
|
|
|
SORT_ORDERS.each do |sort|
|
2013-12-23 18:50:36 -05:00
|
|
|
add_index :top_topics, "#{period}_#{sort}_count".to_sym, order: "desc"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|