1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/db/migrate/20190521151142_migrate_profile_to_statistic_profile.rb

34 lines
879 B
Ruby
Raw Normal View History

# frozen_string_literal:true
2023-02-24 17:26:55 +01:00
# From this migration, we split the user's profile into multiple tables:
# StatisticProfile is intended to keep anonymous statisttical data about the user after his account was deleted
class MigrateProfileToStatisticProfile < ActiveRecord::Migration[4.2]
def up
User.all.each do |u|
p = u.profile
Rails.logger.warn "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
Rails.logger.warn "User #{sp.user_id} has no profile" and next unless p
2023-02-24 17:26:55 +01:00
p.update(
gender: sp.gender,
birthday: sp.birthday
)
end
end
end