1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/db/migrate/20190521151142_migrate_profile_to_statistic_profile.rb
2019-06-11 10:02:48 +02:00

30 lines
662 B
Ruby

class MigrateProfileToStatisticProfile < ActiveRecord::Migration
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