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

24 lines
789 B
Ruby

class MigrateUserToInvoicingProfile < ActiveRecord::Migration
def up
# first, check the footprints
puts 'Checking all invoices footprints. This may take a while...'
Invoice.where.not(footprint: nil).order(:created_at).all.each do |i|
raise "Invalid footprint for invoice #{i.id}" unless i.check_footprint
end
# if everything is ok, proceed with migration
Invoice.order(:created_at).all.each do |i|
i.update_column('invoicing_profile_id', i.user.invoicing_profile.id)
i.update_column('user_id', nil)
i.chain_record
end
end
def down
Invoice.order(:created_at).all.each do |i|
i.update_column('user_id', i.invoicing_profile.user_id)
i.update_column('invoicing_profile_id', nil)
i.chain_record
end
end
end