m160312_050000_create_user   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 22
dl 0
loc 36
c 1
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 6 2
A up() 0 24 3
1
<?php
2
3
use yii\db\Migration;
4
use toir427\admin\components\Configs;
5
6
class m160312_050000_create_user extends Migration
7
{
8
9
    public function up()
10
    {
11
        $tableOptions = null;
12
        if ($this->db->driverName === 'mysql') {
13
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
14
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
15
        }
16
17
        $userTable = Configs::instance()->userTable;
18
        $db = Configs::userDb();
19
20
        // Check if the table exists
21
        if ($db->schema->getTableSchema($userTable, true) === null) {
22
            $this->createTable($userTable, [
23
                'id' => $this->primaryKey(),
24
                'username' => $this->string(32)->notNull(),
25
                'auth_key' => $this->string(32)->notNull(),
26
                'password_hash' => $this->string()->notNull(),
27
                'password_reset_token' => $this->string(),
28
                'email' => $this->string()->notNull(),
29
                'status' => $this->smallInteger()->notNull()->defaultValue(10),
30
                'created_at' => $this->integer()->notNull(),
31
                'updated_at' => $this->integer()->notNull(),
32
                ], $tableOptions);
33
        }
34
    }
35
36
    public function down()
37
    {
38
        $userTable = Configs::instance()->userTable;
39
        $db = Configs::userDb();
40
        if ($db->schema->getTableSchema($userTable, true) !== null) {
41
            $this->dropTable($userTable);
42
        }
43
    }
44
}
45