cirandas.net

ref: master

plugins/orders/db/migrate/20130719132245_create_orders_plugin_tables.rb


 1
 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
class CreateOrdersPluginTables < ActiveRecord::Migration
  def self.up
    # check if distribution plugin already moved tables
    return if ApplicationRecord.connection.table_exists? :orders_plugin_orders

    create_table :orders_plugin_orders do |t|
      t.integer  :profile_id
      t.integer  :consumer_id
      t.integer  :supplier_delivery_id
      t.integer  :consumer_delivery_id
      t.decimal  :total_collected
      t.decimal  :total_payed
      t.string   :status
      t.integer  :code
      t.datetime :created_at
      t.datetime :updated_at
    end

    add_index :orders_plugin_orders, [:consumer_delivery_id]
    add_index :orders_plugin_orders, [:consumer_id]
    add_index :orders_plugin_orders, [:profile_id]
    add_index :orders_plugin_orders, [:status]
    add_index :orders_plugin_orders, [:supplier_delivery_id]

    create_table :orders_plugin_products do |t|
      t.integer  :product_id
      t.integer  :order_id
      t.decimal  :quantity_asked,     :default => 0.0
      t.decimal  :quantity_allocated, :default => 0.0
      t.decimal  :quantity_payed,     :default => 0.0
      t.decimal  :price_asked,        :default => 0.0
      t.decimal  :price_allocated,    :default => 0.0
      t.decimal  :price_payed,        :default => 0.0
      t.datetime :created_at
      t.datetime :updated_at
    end

    add_index :orders_plugin_products, [:order_id]
    add_index :orders_plugin_products, [:product_id]

  end

  def self.down
    drop_table :orders_plugin_orders
    drop_table :orders_plugin_products
  end
end