Class: CreateEcommerceTables

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/ecommerce/templates/migration.rb

Class Method Summary collapse

Class Method Details

.downObject



50
51
52
53
54
55
56
# File 'lib/generators/ecommerce/templates/migration.rb', line 50

def self.down
  drop_table :products
  drop_table :photos
  drop_table :carts
  drop_table :cart_items
  drop_table :payment_notifications
end

.upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/ecommerce/templates/migration.rb', line 2

def self.up

  # Products
  create_table :products do |t|
    t.string :name, :null => false
    t.string :permalink, :null => false
    t.text :descr
    t.column :price, :decimal, :precision => 8, :scale => 2, :default => 0
    t.column :sale_price, :decimal, :precision => 8, :scale => 2, :default => 0
    t.text :meta_description
    t.text :meta_keywords
    t.string :tags
    t.int :shipping_weight
    t.timestamps
  end

  # Each product has_many :photos
  create_table :photos do |t|
    t.integer :product_id
    t.string :photo_file_name
    t.string :photo_content_type
    t.integer :photo_file_size
    t.datetime :photo_updated_at
    t.timestamps
  end

  create_table :carts do |t|
    t.datetime :purchased_at
    t.timestamps
  end

  create_table :cart_items do |t|
    t.integer :cart_id
    t.integer :product_id
    t.integer :quantity
  end

  # PayPal -- how they let us know when a payment has cleared
  create_table :payment_notifications do |t|
    t.text :params
    t.integer :cart_id
    t.string :status
    t.string :transaction_id
    t.timestamps
  end

end