2020-03-24 16:45:27 +01:00
|
|
|
# frozen_string_literal:true
|
|
|
|
|
|
|
|
class MigrateProfileToStatisticProfile < ActiveRecord::Migration[4.2]
|
2019-06-04 13:33:00 +02:00
|
|
|
def up
|
|
|
|
User.all.each do |u|
|
|
|
|
p = u.profile
|
2022-07-26 17:27:33 +02:00
|
|
|
Rails.logger.warn "User #{u.id} has no profile" and next unless p
|
2019-06-04 13:33:00 +02:00
|
|
|
|
|
|
|
StatisticProfile.create!(
|
|
|
|
user: u,
|
|
|
|
group: u.group,
|
2019-06-06 13:58:49 +02:00
|
|
|
role: u.roles.first,
|
2019-06-04 13:33:00 +02:00
|
|
|
gender: p.gender,
|
2019-06-06 16:54:09 +02:00
|
|
|
birthday: p.birthday,
|
|
|
|
created_at: u.created_at
|
2019-06-04 13:33:00 +02:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
StatisticProfile.all.each do |sp|
|
|
|
|
p = sp.user.profile
|
2022-07-26 17:27:33 +02:00
|
|
|
Rails.logger.warn "User #{sp.user_id} has no profile" and next unless p
|
2019-06-04 13:33:00 +02:00
|
|
|
|
|
|
|
p.update_attributes(
|
|
|
|
gender: sp.gender,
|
|
|
|
birthday: sp.birthday
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|