class CreateAdStatistics < ActiveRecord::Migration
  def up
  	#广告项展示统计
    create_table :ad_item_show_statistics do |t|
    	#广告项id
    	t.column :ad_item_id, :integer, :null=>false
    	#微信id
    	t.column :wx_uid,:integer, :null=>false
    	# IP
      t.column :ip,      :string, :limit=>32
    	#展示次数
    	t.column :show_times,:integer, :null=>false
    	# 最后一次展示时间
      t.column   :show_last_time,   :datetime
      t.timestamps
    end

    add_index :ad_item_show_statistics, :ad_item_id    
    add_index :ad_item_show_statistics, :wx_uid  
    add_index :ad_item_show_statistics, [:wx_uid, :ad_item_id], :unique => true

	#广告项点击统计
    create_table :ad_item_click_statistics do |t|
    	#广告项id
    	t.column :ad_item_id, :integer, :null=>false
    	#微信id
    	t.column :wx_uid, :integer, :null=>false
    	# IP
      t.column :ip,      :string, :limit=>32
    	#点击次数
    	t.column :click_times,:integer, :null=>false
    	# 最后一次点击时间
      t.column   :click_last_time,   :datetime
      t.timestamps
    end

    add_index :ad_item_click_statistics, :ad_item_id
    add_index :ad_item_click_statistics, :wx_uid  
    add_index :ad_item_click_statistics, [:wx_uid, :ad_item_id], :unique => true
  end

  def down
  	drop_table :ad_item_show_statistics
  	drop_table :ad_item_click_statistics
  end
end
