20161017200001_create_users.rb 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # encoding:utf-8
  2. class CreateUsers < ActiveRecord::Migration
  3. def self.up
  4. create_table :users, {:options => 'AUTO_INCREMENT = 600101'} do |t|
  5. #电话
  6. t.string :tel, :limit => 20, :null => false
  7. #交易密码
  8. t.string :trade_pwd, :null => false, :default => ""
  9. t.boolean :is_certification, :default => false
  10. #身份证号码
  11. t.string :identity_card, :limit => 18
  12. t.string :real_name, :limit => 64
  13. t.datetime :birthday
  14. t.string :nickname, :limit => 100
  15. t.string :city, :limit => 20
  16. t.string :country, :limit => 20
  17. t.string :province, :limit => 20
  18. #用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
  19. t.integer :sex, :limit => 1, :default => 0
  20. t.column :age, :integer
  21. t.string :head
  22. t.integer :invite_id
  23. t.integer :signup_channel_id
  24. t.string :signup_ip
  25. #是否黑名单,黑名单用户不能代金券和代金券支付商品
  26. t.boolean :is_black_user, :default=>0
  27. t.timestamps
  28. end
  29. add_index :users, :tel, :unique => true
  30. add_index :users, :invite_id
  31. create_table :wx_users do |t|
  32. t.integer :user_id
  33. t.integer :invite_id, :default => 0
  34. t.string :mp_openid, :limit => 64
  35. t.string :openid, :limit => 64
  36. t.string :nickname, :limit => 100, :null => false
  37. t.string :unionid, :limit => 64, :null => false
  38. t.string :city, :limit => 20
  39. t.string :country, :limit => 20
  40. t.string :province, :limit => 20
  41. t.integer :sex, :limit => 1, :default => 0
  42. t.string :head
  43. t.boolean :subscribe
  44. #是否注册
  45. t.boolean :is_regist, :default => 0
  46. t.integer :subscribe_time
  47. t.integer :unsubscribe_time
  48. t.integer :last_conversation_at
  49. # 其实是注册渠道,不要被字面意思误以为码id
  50. t.integer :channel_qrcode_id
  51. t.string :signup_ip
  52. #邀请小程序码链接
  53. t.string :invite_qrcode_url
  54. #购买商品佣金
  55. t.integer :product_benefit_rate, :default=>5
  56. #购买项目佣金
  57. t.integer :project_benefit_rate, :default=>1
  58. #二级商品佣金
  59. t.integer :second_product_benefit_rate
  60. #二级项目佣金
  61. t.integer :second_project_benefit_rate
  62. #合伙人 0不是,1是,0曾经是
  63. t.tinyint :copartner_state, :default => 0
  64. #最新的成为合伙人时间
  65. t.datetime :be_copartner_time
  66. #最新的取消合伙人时间
  67. t.datetime :cancel_copartner_time
  68. t.timestamps
  69. end
  70. add_index :wx_users, :mp_openid
  71. add_index :wx_users, :openid
  72. add_index :wx_users, :unionid, :unique => true
  73. add_index :wx_users, :last_conversation_at
  74. add_index :wx_users, :subscribe
  75. add_index :wx_users, :channel_qrcode_id
  76. add_index :wx_users, :invite_id
  77. add_index :wx_users, :user_id
  78. end
  79. def self.down
  80. drop_table :users
  81. drop_table :wx_users
  82. end
  83. end