class CreatePushTmpl < ActiveRecord::Migration
  def self.up
    create_table :push_tmpls do |t|
      # 这里单独可填微信用户id(以逗号分隔)、填all(所有微信用户)、填allUser(所有注册用户)、填sql=xxx(xxx执行结果是WxUserGongzhonghao结构体)
      t.column   :user_id,   :text
      #模板类型
      t.column   :msg_type,   :string
      #强制推送
      t.column   :push_force, :boolean, :default=>false
      #推送人数
      t.column   :push_count, :integer, :default => 0
      #点击人数
      t.column   :click_count, :integer, :default => 0
      #标题
      t.column   :first,   :string
      #内容1
      t.column   :keyword1,   :string
      t.column   :keyword2,   :string
      t.column   :keyword3,   :string
      t.column   :keyword4,   :string
      #内容5
      t.column   :keyword5,   :string
      #备注
      t.column   :remark,   :string
      #点击链接
      t.column   :url,   :string
      #推送次数
      t.column   :times, :integer, :default => 0
      # 最后一次发送时间
      t.column   :last_updated_at, :datetime
      #公众号
      t.column   :wx_gongzhonghao_id, :integer, :default => 1
      t.timestamps
    end
    create_table :push_tmpl_records do |t|
        t.column :wx_uid, :integer, :null=>false
        t.column :push_time, :datetime, :null=>false
        t.column :temp_id, :integer, :null=>false
    end
    add_index :push_tmpl_records, :wx_uid
  end
  def self.down
    drop_table :push_tmpls
    drop_table :push_tmpl_records
  end
end
