m181104_073622_create_wechat_user.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. use yii\db\Migration;
  3. use yii\db\Schema;
  4. class m181104_073622_create_wechat_user extends Migration
  5. {
  6. public $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  7. public function safeUp()
  8. {
  9. /**
  10. * 微信用户基础表
  11. */
  12. $this->createTable('{{%wechat_user}}', [
  13. 'id' => Schema::TYPE_PK,
  14. 'openid' => $this->string(64)->notNull()->unique()->comment('小程序ID'),
  15. 'unionid' => $this->string(64)->null()->unique()->comment('开放平台ID'),
  16. 'tel' => $this->string(11)->null()->unique()->comment('手机号'),
  17. 'nickName' => Schema::TYPE_STRING . "(20) NOT NULL COMMENT '昵称'",
  18. 'avatarUrl' => Schema::TYPE_STRING . "(300) NOT NULL COMMENT '头像'",
  19. 'country' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '国家'",
  20. 'province' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '省份'",
  21. 'city' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '城市'",
  22. 'language' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '语言'",
  23. 'signature' => Schema::TYPE_STRING . "(100) NOT NULL COMMENT '签名' DEFAULT ''",
  24. 'created_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  25. 'updated_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  26. 'status' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '1' COMMENT '状态'",
  27. 'gender' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '1' COMMENT '性别'",
  28. ], $this->tableOptions);
  29. }
  30. public function safeDown()
  31. {
  32. echo "m181104_073622_create_wechat_user cannot be reverted.\n";
  33. $this->dropTable('{{%wechat_user}}');
  34. return false;
  35. }
  36. /*
  37. // Use up()/down() to run migration code without a transaction.
  38. public function up()
  39. {
  40. }
  41. public function down()
  42. {
  43. echo "m181104_073622_create_wechat_user cannot be reverted.\n";
  44. return false;
  45. }
  46. */
  47. }