2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
class MoveColumnsToUserStats < ActiveRecord::Migration[4.2]
|
2013-10-04 11:28:49 +08:00
|
|
|
def up
|
|
|
|
add_column :user_stats, :topics_entered, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :time_read, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :days_visited, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :posts_read_count, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :likes_given, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :likes_received, :integer, default: 0, null: false
|
|
|
|
add_column :user_stats, :topic_reply_count, :integer, default: 0, null: false
|
|
|
|
|
2013-10-04 16:06:32 +08:00
|
|
|
execute "UPDATE user_stats s
|
2013-10-04 11:28:49 +08:00
|
|
|
SET topics_entered = u.topics_entered,
|
|
|
|
time_read = u.time_read,
|
|
|
|
days_visited = u.days_visited,
|
|
|
|
posts_read_count = u.posts_read_count,
|
|
|
|
likes_given = u.likes_given,
|
|
|
|
likes_received = u.likes_received,
|
|
|
|
topic_reply_count = u.topic_reply_count
|
2013-10-04 16:06:32 +08:00
|
|
|
FROM users u WHERE u.id = s.user_id
|
2023-01-09 19:59:41 +08:00
|
|
|
"
|
2013-10-04 11:28:49 +08:00
|
|
|
|
|
|
|
remove_column :users, :topics_entered
|
|
|
|
remove_column :users, :time_read
|
|
|
|
remove_column :users, :days_visited
|
|
|
|
remove_column :users, :posts_read_count
|
|
|
|
remove_column :users, :likes_given
|
|
|
|
remove_column :users, :likes_received
|
|
|
|
remove_column :users, :topic_reply_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
add_column :users, :topics_entered, :integer
|
|
|
|
add_column :users, :time_read, :integer
|
|
|
|
add_column :users, :days_visited, :integer
|
|
|
|
add_column :users, :posts_read_count, :integer
|
|
|
|
add_column :users, :likes_given, :integer
|
|
|
|
add_column :users, :likes_received, :integer
|
|
|
|
add_column :users, :topic_reply_count, :integer
|
|
|
|
|
2013-10-04 16:06:32 +08:00
|
|
|
execute "UPDATE users s
|
2013-10-04 11:28:49 +08:00
|
|
|
SET topics_entered = u.topics_entered,
|
|
|
|
time_read = u.time_read,
|
|
|
|
days_visited = u.days_visited,
|
|
|
|
posts_read_count = u.posts_read_count,
|
|
|
|
likes_given = u.likes_given,
|
|
|
|
likes_received = u.likes_received,
|
|
|
|
topic_reply_count = u.topic_reply_count
|
2013-10-04 16:06:32 +08:00
|
|
|
FROM user_stats u WHERE s.id = u.user_id
|
2023-01-09 19:59:41 +08:00
|
|
|
"
|
2013-10-04 11:28:49 +08:00
|
|
|
|
|
|
|
remove_column :user_stats, :topics_entered
|
|
|
|
remove_column :user_stats, :time_read
|
|
|
|
remove_column :user_stats, :days_visited
|
|
|
|
remove_column :user_stats, :posts_read_count
|
|
|
|
remove_column :user_stats, :likes_given
|
|
|
|
remove_column :user_stats, :likes_received
|
|
|
|
remove_column :user_stats, :topic_reply_count
|
|
|
|
end
|
|
|
|
end
|