1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +01:00
fab-manager/db/migrate/20190521124609_migrate_profile_to_invoicing_profile.rb

34 lines
761 B
Ruby

class MigrateProfileToInvoicingProfile < ActiveRecord::Migration
def up
Profile.all.each do |p|
ip = InvoicingProfile.create!(
user: p.user,
first_name: p.first_name,
last_name: p.last_name
)
p.address&.update_attributes(
placeable: ip
)
p.organization&.update_attributes(
invoicing_profile_id: ip.id
)
end
end
def down
InvoicingProfile.all.each do |ip|
profile = ip.user.profile
profile.update_attributes(
first_name: ip.first_name,
last_name: ip.last_name,
)
ip.address&.update_attributes(
placeable: profile
)
ip.organization&.update_attributes(
profile_id: profile.id
)
end
end
end