# encoding:utf-8
class CreatePromotions < ActiveRecord::Migration
  def up
    #促销表
    create_table :promotions do |t|
      # 促销名称
      t.column :name, :string,:limit => 128
      #开始时间
      t.column :begin_time,:datetime
      #结束时间
      t.column :end_time,:datetime
      # 是否首单
      t.column :is_first, :boolean, :default=>1
      # 多买多送
      t.column :is_more, :boolean, :default=>1
      # 订单类型
      t.column :order_type, :integer, :limit => 11, :default => 0
      # 最小金额
      t.column :min_total, :integer, :limit => 11, :default => 0
      # 最大金额
      t.column :max_total, :integer, :limit => 11, :default => 0
      # 买品1
      t.column :prod1, :integer, :limit => 11, :default => 0
      # 数量1
      t.column :nums1, :integer, :limit => 11, :default => 0
      # 买品2
      t.column :prod2, :integer, :limit => 11, :default => 0
      # 数量3
      t.column :nums2, :integer, :limit => 11, :default => 0
      # 买品3
      t.column :prod3, :integer, :limit => 11, :default => 0
      # 数量3
      t.column :nums3, :integer, :limit => 11, :default => 0
      # 赠品1
      t.column :send_prod1, :integer, :limit => 11, :default => 0
      # 数量1
      t.column :send_nums1, :integer, :limit => 11, :default => 0
      # 赠品2
      t.column :send_prod2, :integer, :limit => 11, :default => 0
      # 赠品数量2
      t.column :send_nums2, :integer, :limit => 11, :default => 0
      # 赠品3
      t.column :send_prod3, :integer, :limit => 11, :default => 0
      # 赠品数量3
      t.column :send_nums3, :integer, :limit => 11, :default => 0
      # 状态
      t.column :is_enable, :boolean, :default=>1
      # 赠代办金
      t.column :cash, :integer, :limit => 11, :default => 0
      # 赠积分
      t.column :cent, :integer, :limit => 11, :default => 0
      t.timestamps
    end
    add_index :shop_applications, :user_id
    add_index :shop_applications, :wx_user_id
    add_index :promotions, :begin_time
    add_index :promotions, :end_time
  end

  def down
    remove_index :shop_applications, :user_id
    remove_index :shop_applications, :wx_user_id
    drop_table :promotions
  end

end
