class AddUserExtras < ActiveRecord::Migration def up # NOTE: our user table is getting bloated, we probably want to split it for performance # put lesser used columns into a user_extras table and frequently used ones here. add_column :users, :likes_given, :integer, null: false, default: 0 add_column :users, :likes_received, :integer, null: false, default: 0 add_column :users, :topic_reply_count, :integer, null: false, default: 0 # NOTE: to keep migrations working through refactorings we avoid externalizing this stuff. # even though a helper method may make sense execute < p.user_id AND p.deleted_at IS NULL AND t.deleted_at IS NULL GROUP BY p.user_id ) Z WHERE Z.user_id = u.id SQL end def down remove_column :users, :likes_given remove_column :users, :likes_received remove_column :users, :topic_reply_count end end