Completed
Push — master ( 61b75c...99e722 )
by Jeff
03:37
created

m161031_091506_create_user_table::up()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `user`.
7
 */
8
// @codingStandardsIgnoreLine
9
class m161031_091506_create_user_table extends Migration
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function up()
15
    {
16
        $tableOptions = null;
17
        if ($this->db->driverName === 'mysql') {
18
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
19
        }
20
21
        $this->createTable('user', [
22
            'username' => $this->string(64)->notNull(),
23
            'hash' => $this->string(64),
24
            'authkey' => $this->string(64)->notNull(),
25
            'access_token' => $this->string(64)->notNull(),
26
            'added_at' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP'),
27
            'last_login_at' => $this->timestamp()->null(),
28
        ], $tableOptions);
29
30
        $this->addPrimaryKey(
31
            'pk_user',
32
            'user',
33
            ['username']
34
        );
35
36
        \app\models\User::create('admin', 'admin');
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function down()
43
    {
44
        $this->dropTable('user');
45
    }
46
}
47