m160726_093217_create_user_table.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. use yii\db\Migration;
  3. use yii\db\mysql\Schema;
  4. /**
  5. * Handles the creation for table `{{%user}}`.
  6. */
  7. class m160726_093217_create_user_table extends Migration
  8. {
  9. /**
  10. * @inheritdoc
  11. */
  12. public function up()
  13. {
  14. $tableOptions = null;
  15. if ($this->db->driverName === 'mysql') {
  16. $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  17. }
  18. // user
  19. $this->createTable('{{%user}}', [
  20. 'id' => Schema::TYPE_PK,
  21. 'username' => $this->string(255)->notNull()->unique(),
  22. 'auth_key' => Schema::TYPE_STRING . "(32) NOT NULL",
  23. 'password_hash' => Schema::TYPE_STRING . "(255) NOT NULL",
  24. 'password_reset_token' => Schema::TYPE_STRING . "(255) NULL",
  25. 'email' => Schema::TYPE_STRING . "(255) NOT NULL",
  26. 'created_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  27. 'updated_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  28. 'login_at' => Schema::TYPE_INTEGER . "(11) NULL",
  29. 'blocked_at' => $this->integer()->null(),
  30. 'confirmed_at' => $this->integer()->null(),
  31. 'access_token' => $this->string(32)->null(),
  32. 'expired_at' => $this->integer()->null()
  33. ], $tableOptions);
  34. // profile
  35. $this->createTable('{{%user_profile}}', [
  36. 'user_id' => Schema::TYPE_PK,
  37. 'money' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT 0",
  38. 'avatar' => $this->string(255)->notNull()->defaultValue(''),
  39. 'signature' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT ''",
  40. 'gender' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0'",
  41. 'qq' => $this->string(20),
  42. 'phone' => $this->string(20),
  43. 'province' => $this->smallInteger(4),
  44. 'city' => $this->smallInteger(4),
  45. 'area' => $this->smallInteger(4),
  46. 'locale' => Schema::TYPE_STRING . "(32) NOT NULL DEFAULT 'zh-CN'",
  47. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  48. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL"
  49. ], $tableOptions);
  50. /*$this->insert('{{%user}}', [
  51. 'username' => 'hehe',
  52. 'auth_key' => '1lQl4TG6sYlyWRqXZEWL0ZhQkPATVnMs',
  53. 'password_hash' => '$2y$13$lYlhIcBcs6jBr7yTd6YrWueckcs.Cvx70juIHs6wEfjtUwnA318VW',
  54. 'email' => 'hehe@xxx.com',
  55. 'created_at' => 1441766741,
  56. 'updated_at' => 1441766741,
  57. 'login_at' => '1441766741',
  58. 'confirmed_at' => '1441766741'
  59. ]);
  60. $this->insert('{{%user_profile}}', [
  61. 'user_id' => 1,
  62. 'locale' => 'zh-CN',
  63. 'created_at' => 1441766741,
  64. 'updated_at' => 1441766741,
  65. ]);*/
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function down()
  71. {
  72. $this->dropTable('{{%user}}');
  73. $this->dropTable('{{%user_profile}}');
  74. }
  75. }