m130524_201442_init.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use yii\db\Migration;
  3. class m130524_201442_init extends Migration
  4. {
  5. public function up()
  6. {
  7. $tableOptions = null;
  8. if ($this->db->driverName === 'mysql') {
  9. // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
  10. $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
  11. }
  12. $this->createTable('{{%user}}', [
  13. 'id' => $this->primaryKey(),
  14. 'username' => $this->string()->notNull()->unique(),
  15. 'auth_key' => $this->string(32)->notNull(),
  16. 'password_hash' => $this->string()->notNull(),
  17. 'password_reset_token' => $this->string()->unique(),
  18. 'access_token'=>$this->string(),
  19. 'email' => $this->string()->notNull()->unique(),
  20. 'status' => $this->smallInteger()->notNull()->defaultValue(10),
  21. 'created_at' => $this->integer()->notNull(),
  22. 'updated_at' => $this->integer()->notNull(),
  23. ], $tableOptions);
  24. $this->createTable('{{%admin_user}}', [
  25. 'id' => $this->primaryKey(),
  26. 'username' => $this->string()->notNull()->unique(),
  27. 'auth_key' => $this->string(32)->notNull(),
  28. 'password_hash' => $this->string()->notNull(),
  29. 'password_reset_token' => $this->string()->unique(),
  30. 'email' => $this->string()->notNull()->unique(),
  31. 'status' => $this->smallInteger()->notNull()->defaultValue(10),
  32. 'created_at' => $this->integer()->notNull(),
  33. 'updated_at' => $this->integer()->notNull(),
  34. ], $tableOptions);
  35. }
  36. public function down()
  37. {
  38. $this->dropTable('{{%user}}');
  39. $this->dropTable('{{%admin_user}}');
  40. }
  41. }