Change relationship of invoices #390
This change will allow us to have invoices for more than one order/delivery in the future. There are no UI changes for now.
This commit is contained in:
parent
9f919c3e54
commit
460cf1e82c
13 changed files with 70 additions and 38 deletions
21
db/migrate/20160217134742_change_invoice_relation.rb
Normal file
21
db/migrate/20160217134742_change_invoice_relation.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class ChangeInvoiceRelation < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :deliveries, :invoice_id, :integer
|
||||
execute 'UPDATE deliveries SET invoice_id = (SELECT id FROM invoices WHERE delivery_id = deliveries.id)'
|
||||
remove_column :invoices, :delivery_id
|
||||
|
||||
add_column :orders, :invoice_id, :integer
|
||||
execute 'UPDATE orders SET invoice_id = (SELECT id FROM invoices WHERE order_id = orders.id)'
|
||||
remove_column :invoices, :order_id
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :invoices, :delivery_id
|
||||
execute 'UPDATE invoices SET delivery_id = (SELECT id FROM deliveries WHERE invoice_id = invoices.id)'
|
||||
remove_column :deliveries, :invoice_id, :integer
|
||||
|
||||
add_column :invoices, :order_id
|
||||
execute 'UPDATE invoices SET order_id = (SELECT id FROM orders WHERE invoice_id = invoices.id)'
|
||||
remove_column :orders, :invoice_id, :integer
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue