Created
March 24, 2017 12:36
-
-
Save calcio/a792146f1b74c617ea4af0033d8f0cca to your computer and use it in GitHub Desktop.
Migrate example - serie Vitrine project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\db\Migration; | |
class m170104_184151_users extends Migration | |
{ | |
public function up() | |
{ | |
$tableOptions = null; | |
if ($this->db->driverName === 'mysql') { | |
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci | |
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; | |
} | |
$this->createTable('users', [ | |
'id' => $this->primaryKey(), | |
'username' => $this->string()->notNull()->unique(), | |
'authKey' => $this->string(32)->notNull(), | |
'passwordHash' => $this->string()->notNull(), | |
'passwordResetToken' => $this->string()->unique(), | |
'email' => $this->string()->notNull()->unique(), | |
'status' => $this->smallInteger()->notNull()->defaultValue(10), | |
'created_at' => $this->integer()->notNull(), | |
'updated_at' => $this->integer()->notNull(), | |
], $tableOptions); | |
$this->insert('users', [ | |
'username' => 'admin', | |
'authKey' => Yii::$app->security->generateRandomString(), | |
'passwordHash' => Yii::$app->getSecurity()->generatePasswordHash('admin'), | |
'email' => 'admin@mail.com', | |
'status' => '10', | |
]); | |
} | |
public function down() | |
{ | |
$this->dropTable('users'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment