M170304142349CreateProfileTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 29 2
A down() 0 4 1
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\migrations;
14
15
use rhosocial\user\User;
16
use rhosocial\user\Profile;
17
18
/**
19
 * Create Profile Table.
20
 *
21
 * This migration is equivalent to:
22
```SQL
23
CREATE TABLE `profile` (
24
    `guid` varbinary(16) NOT NULL COMMENT 'User GUID',
25
    `nickname` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Nickname',
26
    `first_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'First Name',
27
    `last_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Last Name',
28
    `gravatar_type` smallint(6) NOT NULL DEFAULT '0',
29
    `gravatar` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
30
    `gender` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Gender',
31
    `timezone` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'UTC',
32
    `individual_sign` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Individual Sign',
33
    `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At',
34
    `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At',
35
    PRIMARY KEY (`guid`),
36
    KEY `user_nickname_normal` (`nickname`) USING BTREE,
37
    KEY `user_first_name_normal` (`first_name`) USING BTREE,
38
    KEY `user_last_name_normal` (`last_name`) USING BTREE,
39
    KEY `user_gender_normal` (`gender`) USING BTREE,
40
    KEY `user_timezone_normal` (`timezone`) USING BTREE,
41
    KEY `user_profile_created_at_normal` (`created_at`) USING BTREE,
42
    CONSTRAINT `user_profile_fk` FOREIGN KEY (`guid`) REFERENCES `user` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE
43
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Profile';
44
```SQL
45
 *
46
 * If you want to go back, please execute `yii migrate/to rhosocial\user\migrations\M170304142349CreateProfileTable`,
47
 * instead of droping profile table yourself.
48
 * Note: this execution will reverse all the migrations after this migration.
49
 *
50
 * @version 1.0
51
 * @author vistart <[email protected]>
52
 */
53
class M170304142349CreateProfileTable extends Migration
54
{
55
    public function up()
56
    {
57
        $tableOptions = null;
0 ignored issues
show
Unused Code introduced by
$tableOptions is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
        if ($this->db->driverName === 'mysql') {
59
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
60
            $tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Profile'";
61
            $this->createTable(Profile::tableName(), [
62
                'guid' => $this->varbinary(16)->notNull()->comment('User GUID'),
63
                'nickname' => $this->varchar(255)->notNull()->comment('Nickname'),
64
                'first_name' => $this->varchar(255)->notNull()->defaultValue('')->comment('First Name'),
65
                'last_name' => $this->varchar(255)->notNull()->defaultValue('')->comment('Last Name'),
66
                'gravatar_type' => $this->smallInteger()->notNull()->defaultValue(0)->comment('Gravatar Type'),
67
                'gravatar'=> $this->varchar(255)->notNull()->defaultValue('')->comment('Gravatar'),
68
                'gender' => $this->tinyInteger(1)->notNull()->defaultValue(1)->comment('Gender'),
69
                'timezone' => $this->varchar(255)->charset('utf8')->collate('utf8_unicode_ci')->notNull()->defaultValue('UTC')->comment('Timezone'),
70
                'individual_sign' => $this->text()->notNull()->comment('Individual Sign'),
71
                'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'),
72
                'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'),
73
            ], $tableOptions);
74
        }
75
        $this->addPrimaryKey('user_guid_profile_pk', Profile::tableName(), 'guid');
76
        $this->addForeignKey('user_profile_fk', Profile::tableName(), 'guid', User::tableName(), 'guid', 'CASCADE', 'CASCADE');
77
        $this->createIndex('user_nickname_normal', Profile::tableName(), 'nickname');
78
        $this->createIndex('user_first_name_normal', Profile::tableName(), 'first_name');
79
        $this->createIndex('user_last_name_normal', Profile::tableName(), 'last_name');
80
        $this->createIndex('user_gender_normal', Profile::tableName(), 'gender');
81
        $this->createIndex('user_timezone_normal', Profile::tableName(), 'timezone');
82
        $this->createIndex('user_profile_created_at_normal', Profile::tableName(), 'created_at');
83
    }
84
85
    public function down()
86
    {
87
        $this->dropTable(Profile::tableName());
88
    }
89
90
    /*
91
    // Use safeUp/safeDown to run migration code within a transaction
92
    public function safeUp()
93
    {
94
    }
95
96
    public function safeDown()
97
    {
98
    }
99
    */
100
}
101