Class: ShopCartModelMigration

Inherits:
Migration
  • Object
show all
Defined in:
lib/migrations/04_shop_cart_model.rb

Class Method Summary collapse

Class Method Details

.down(site) ⇒ Object



26
27
28
29
# File 'lib/migrations/04_shop_cart_model.rb', line 26

def self.down(site)
  site.carts.destroy
  site.cart_pages.destroy
end

.up(site) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/migrations/04_shop_cart_model.rb', line 2

def self.up(site)
  site.records.create_model :carts do |carts|
    add_field :session_id, :string
    add_one   :user, index: true
    add_many  :product_holds, foreign_key: 'cart', destroy: true
    add_field :created_at, :time
    add_field :updated_at, :time
    add_field :hold_duration, :integer, default: 600
    add_one   :transaction, index: true
    carts.record_class_name = 'Cart'
    
    # permissions
    users_group = site.groups['Users'].id
    carts.view_group = users_group
    carts.create_group = users_group
    carts.update_group = users_group
    carts.delete_group = users_group
  end
  
  site.pages.create_model :cart_pages do |cart_pages|
    cart_pages.record_class_name = 'CartPage'
  end
end