# encoding:utf-8
# 银豆流水表
class CreateSilvers < ActiveRecord::Migration
  def self.up
    create_table :silvers do |t|
      #用户id
      t.belongs_to :user
      t.integer :wx_user_id
      #有正负值
      t.integer :count
      #来源
      t.string :source, :limit => 64
      #充值订单id，认购记录id等等，具体对应情况在model层配置
      t.string :relate_id
      #中文描述
      t.string :remark
      t.timestamps
    end
    add_index  :silvers, :user_id
    add_index  :silvers, :wx_user_id
    add_column :orders,  :dis_amount ,:integer, :limit => 11, :default => 0
    add_column :orders,  :total_silver ,:integer, :limit => 11, :default => 0
    add_column :orders,  :paied_silver ,:integer, :limit => 11, :default => 0
    add_column :orders,  :paied_cash ,:integer, :limit => 11, :default => 0
    add_column :order_details,  :silver ,:integer, :limit => 11, :default => 0
    add_column :order_details,  :dis_amount ,:integer, :limit => 11, :default => 0
    add_column :products, :silver , :integer, :limit => 11, :default => 0
    add_column :products, :use_quan, :boolean,:limit => 1
  end

  def self.down
    drop_table :silvers
    remove_column :orders, :total_silver
    remove_column :orders, :paied_silver
    remove_column :orders, :dis_amount
    remove_column :products, :silver
    remove_column :products, :use_quan
    remove_column :order_details, :silver
    remove_column :order_details, :dis_amount
  end
end
