-
Notifications
You must be signed in to change notification settings - Fork 2
/
m170104_184151_users.php
executable file
·50 lines (43 loc) · 1.58 KB
/
m170104_184151_users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?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->timestamp()->defaultExpression('CURRENT_TIMESTAMP')->notNull(),
'updated_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP')->notNull(),
], $tableOptions);
$this->insert('users', [
'username' => 'admin',
'authKey' => Yii::$app->security->generateRandomString(),
'passwordHash' => Yii::$app->getSecurity()->generatePasswordHash('admin'),
'email' => 'admin@mail.com',
]);
}
public function down()
{
$this->dropTable('users');
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}