End chapter 10
[depot.git] / db / migrate / 20090304153613_create_line_items.rb
1 class CreateLineItems < ActiveRecord::Migration
2 def self.up
3 create_table :line_items do |t|
4 t.integer :product_id, :null => false
5 t.integer :order_id, :null => false
6 t.integer :quantity, :null => false
7 t.decimal :total_price, :null => false, :precision => 8, :scale => 2
8
9 t.timestamps
10 end
11
12 execute "alter table line_items add constraint fk_line_item_products
13 foreign key (product_id) references products(id)"
14
15 execute "alter table line_items add constraint fk_line_item_orders
16 foreign key (order_id) references orders(id)"
17
18 end
19
20 def self.down
21 drop_table :line_items
22 end
23 end