class AddParticularToCustomers < ActiveRecord::Migration
  
  def self.up
    add_column :customers, :particular_idem, :boolean
    add_column :customers, :particular_send_id, :integer
    add_column :customers, :particular_bill_id, :integer
    
    Customer.all.each do |customer|
      customer.particular_bill = Particular.new
      customer.particular_bill.skip_validation = true
      customer.particular_bill.organisation = customer.organisation
      customer.particular_bill.name = customer.name
      customer.particular_bill.firstname = customer.firstname
      customer.particular_bill.address_2 = customer.address
      customer.particular_bill.address_3 = customer.address2
      customer.particular_bill.cp = customer.cp
      customer.particular_bill.city = customer.city
      customer.particular_bill.country = customer.country
      customer.particular_bill.tel = customer.phone
      customer.particular_bill.email = customer.email
      
      customer.particular_send = Particular.new
      customer.particular_send.skip_validation = true
      
      customer.particular_idem = true
      customer.save  
    end
  end

  def self.down
    remove_column :customers, :particular_idem
    remove_column :customers, :particular_send_id
    remove_column :customers, :particular_bill_id
    
  end    

end
