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

m161031_091506_create_user_table   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 24 2
A down() 0 4 1
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