mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
32 lines
697 B
Ruby
32 lines
697 B
Ruby
# frozen_string_literal:true
|
|
|
|
class MigrateProfileToStatisticProfile < ActiveRecord::Migration[4.2]
|
|
def up
|
|
User.all.each do |u|
|
|
p = u.profile
|
|
puts "WARNING: User #{u.id} has no profile" and next unless p
|
|
|
|
StatisticProfile.create!(
|
|
user: u,
|
|
group: u.group,
|
|
role: u.roles.first,
|
|
gender: p.gender,
|
|
birthday: p.birthday,
|
|
created_at: u.created_at
|
|
)
|
|
end
|
|
end
|
|
|
|
def down
|
|
StatisticProfile.all.each do |sp|
|
|
p = sp.user.profile
|
|
puts "WARNING: User #{sp.user_id} has no profile" and next unless p
|
|
|
|
p.update_attributes(
|
|
gender: sp.gender,
|
|
birthday: sp.birthday
|
|
)
|
|
end
|
|
end
|
|
end
|