# encoding:utf-8
class CreateProductWarns < ActiveRecord::Migration
  def up
    #商品生产预警
    create_table :product_warns do |t|
      # 统计时间
      t.column :happen_time,:date
      # 商品ID
      t.column :product_id, :integer, :limit => 4, :null => false, :default => 0
      # 商品名称
      t.column :product_name, :string, :limit => 128,  :null => false,:default => ""
      # 商品类型
      t.column :product_type, :string, :limit => 128,  :null => false,:default => ""
      # 商品规格
      t.column :product_size, :string, :limit => 128,  :null => false,:default => ""
      # 近90日销售
      t.column :sale_90, :integer, :limit => 11, :null => false, :default => 0
      # 近30日销售
      t.column :sale_30, :integer, :limit => 11, :null => false, :default => 0
      # 近10日销售
      t.column :sale_10, :integer, :limit => 11, :null => false, :default => 0
      # 现有库存数
      t.column :now_count, :integer, :limit => 11, :null => false, :default => 0
      # 生产周期
      t.column :product_cycle, :integer, :limit => 11, :null => false, :default => 0
      # 备货周期
      t.column :stock_cycle, :integer, :limit => 11, :null => false, :default => 0
      # 最低进货量
      t.column :min_purchase, :integer, :limit => 11, :null => false, :default => 0
      # 历史日均销量
      t.column :history_day_sales, :integer, :limit => 11, :null => false, :default => 0
      # 建议生产数
      t.column :recommend_count, :integer, :limit => 11, :null => false, :default => 0
      t.timestamps
    end

    add_column :products, :product_cycle, :integer, :limit => 11, :null => false, :default => 0
    add_column :products, :stock_cycle, :integer, :limit => 11, :null => false, :default => 0
    add_column :products, :min_purchase, :integer, :limit => 11, :null => false, :default => 0

  end

  def down
    drop_table :product_warns
  end
end




