Completed
Push — master ( 30d3de...6bbfea )
by Xu
29:18 queued 23:02
created

m180223_102927Create_user_extra_table::safeUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
use yii\db\Migration;
4
5
class m180223_102927Create_user_extra_table extends Migration
6
{
7
    public $tableName = '{{%user_extra}}';
8
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function safeUp()
13
    {
14
        $tableOptions = null;
15
        if ($this->db->driverName === 'mysql') {
16
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
17
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
18
        }
19
        /**
20
         * 创建用户附表
21
         */
22
        $this->createTable($this->tableName, [
23
            'user_id' => $this->integer()->unsigned()->notNull()->comment('User ID'),
24
            'login_ip' => $this->string()->comment('Login Ip'),
25
            'login_at' => $this->integer()->unsigned()->comment('Login At'),
26
            'login_num' => $this->integer()->unsigned()->defaultValue(0)->comment('Login Num'),
27
            'last_visit' => $this->integer()->unsigned()->comment('Last Visit'),
28
            'views' => $this->integer()->unsigned()->defaultValue(0)->comment('Views'),
29
            'supports' => $this->integer()->unsigned()->defaultValue(0)->comment('Supports'),
30
            'followers' => $this->integer()->unsigned()->defaultValue(0)->comment('Followers'),
31
        ], $tableOptions);
32
        $this->addPrimaryKey('{{%user_extra_pk}}', $this->tableName, 'user_id');
33
        $this->addForeignKey('{{%user_extra_fk_1}}', $this->tableName, 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT');
34
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function safeDown()
41
    {
42
        $this->dropTable($this->tableName);
43
    }
44
45
    /*
46
    // Use up()/down() to run migration code without a transaction.
47
    public function up()
48
    {
49
50
    }
51
52
    public function down()
53
    {
54
        echo "M180223102927Create_user_extra_table cannot be reverted.\n";
55
56
        return false;
57
    }
58
    */
59
}
60