class CreatePosterQrcodeTables < ActiveRecord::Migration
  def change
    create_table :poster_qrcode_records do |t|

        t.column :wx_uid, :integer, :null=>false
        t.column :parent_relate_id, :integer, :null=>false
        t.column :relate_id, :integer, :null=>false
        t.column :ptype,   :string
        t.column :scan_times,:integer, :null=>false
        t.column :qrcode_url, :string
        t.timestamps
    end

    add_index :poster_qrcode_records, :wx_uid

    create_table :poster_qrcode_scan_records do |t|
      #海报小程序码id
      t.column :poster_qrcode_id, :integer, :null=>false
      #微信id
      t.column :wx_uid, :integer, :null=>false
      # IP
      t.column :ip,      :string, :limit=>32
      #扫码次数
      t.column :scan_times,:integer, :null=>false
      # 最后一次扫码时间
      t.column   :scan_last_time,   :datetime
      t.timestamps
    end
    add_index :poster_qrcode_scan_records, :poster_qrcode_id
    add_index :poster_qrcode_scan_records, :wx_uid  
    add_index :poster_qrcode_scan_records, [:wx_uid, :poster_qrcode_id], :unique => true
  end

  def down
    drop_table :poster_qrcode_records
    drop_table :poster_qrcode_scan_records
  end
end
