discourse/db/migrate/20131223171005_create_top_topics.rb

27 lines
626 B
Ruby
Raw Normal View History

2013-12-23 17:50:36 -06:00
class CreateTopTopics < ActiveRecord::Migration
2014-01-13 18:02:14 -06:00
PERIODS = [:yearly, :monthly, :weekly, :daily]
SORT_ORDERS = [:posts, :views, :likes]
2013-12-23 17:50:36 -06:00
def change
create_table :top_topics, force: true do |t|
2013-12-23 17:50:36 -06:00
t.belongs_to :topic
2014-01-13 18:02:14 -06:00
PERIODS.each do |period|
SORT_ORDERS.each do |sort|
2013-12-23 17:50:36 -06: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 18:02:14 -06:00
PERIODS.each do |period|
SORT_ORDERS.each do |sort|
2013-12-23 17:50:36 -06:00
add_index :top_topics, "#{period}_#{sort}_count".to_sym, order: 'desc'
end
end
end
end