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
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Create User Table. |
19
|
|
|
* |
20
|
|
|
* This migration is equivalent to: |
21
|
|
|
```SQL |
22
|
|
|
CREATE TABLE `user` ( |
23
|
|
|
`guid` varbinary(16) NOT NULL COMMENT 'User GUID', |
24
|
|
|
`id` varchar(16) COLLATE utf8_unicode_ci NOT NULL COMMENT 'User ID No.', |
25
|
|
|
`pass_hash` varchar(80) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Password Hash', |
26
|
|
|
`ip` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'IP Address', |
27
|
|
|
`ip_type` tinyint(3) NOT NULL DEFAULT '4' COMMENT 'IP Address Type', |
28
|
|
|
`created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Created At', |
29
|
|
|
`updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Updated At', |
30
|
|
|
`auth_key` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Authentication Key', |
31
|
|
|
`access_token` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Access Token', |
32
|
|
|
`password_reset_token` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Password Reset Token', |
33
|
|
|
`status` tinyint(3) NOT NULL DEFAULT '1' COMMENT 'Status', |
34
|
|
|
`type` tinyint(3) NOT NULL DEFAULT '0' COMMENT 'Type', |
35
|
|
|
`source` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Source', |
36
|
|
|
PRIMARY KEY (`guid`), |
37
|
|
|
UNIQUE KEY `user_id_unique` (`id`), |
38
|
|
|
KEY `user_auth_key_normal` (`auth_key`), |
39
|
|
|
KEY `user_access_token_normal` (`access_token`), |
40
|
|
|
KEY `user_password_reset_token_normal` (`password_reset_token`), |
41
|
|
|
KEY `user_created_at_normal` (`created_at`), |
42
|
|
|
KEY `user_status_normal` (`status`) USING BTREE, |
43
|
|
|
KEY `user_type_normal` (`type`) USING BTREE, |
44
|
|
|
KEY `user_source_normal` (`source`) USING BTREE |
45
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='User'; |
46
|
|
|
``` |
47
|
|
|
* |
48
|
|
|
* If you want to go back, please execute `yii migrate/to rhosocial\user\migrations\M170304140437CreateUserTable`, |
49
|
|
|
* instead of droping user table yourself. |
50
|
|
|
* Note: this execution will reverse all the migrations after this migration. |
51
|
|
|
* |
52
|
|
|
* @version 1.0 |
53
|
|
|
* @author vistart <[email protected]> |
54
|
|
|
*/ |
55
|
|
|
class M170304140437CreateUserTable extends Migration |
56
|
|
|
{ |
57
|
|
|
public function up() |
58
|
|
|
{ |
59
|
|
|
$tableOptions = null; |
|
|
|
|
60
|
|
|
if ($this->db->driverName === 'mysql') { |
61
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
62
|
|
|
$tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='User'"; |
63
|
|
|
$this->createTable(User::tableName(), [ |
64
|
|
|
'guid' => $this->varbinary(16)->notNull()->comment('User GUID'), |
65
|
|
|
'id' => $this->varchar(16)->notNull()->collate('utf8_unicode_ci')->comment('User ID No.'), |
66
|
|
|
'pass_hash' => $this->varchar(80)->notNull()->collate('utf8_unicode_ci')->comment('Password Hash'), |
67
|
|
|
'ip' => $this->varbinary(16)->notNull()->defaultValue(0)->comment('IP Address'), |
68
|
|
|
'ip_type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(4)->comment('IP Address Type'), |
69
|
|
|
'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'), |
70
|
|
|
'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'), |
71
|
|
|
'auth_key' => $this->varchar(255)->notNull()->defaultValue('')->collate('utf8_unicode_ci')->comment('Authentication Key'), |
72
|
|
|
'access_token' => $this->varchar(255)->notNull()->defaultValue('')->collate('utf8_unicode_ci')->comment('Access Token'), |
73
|
|
|
'password_reset_token' => $this->varchar(255)->notNull()->defaultValue('')->collate('utf8_unicode_ci')->comment('Password Reset Token'), |
74
|
|
|
'status' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(1)->comment('Status'), |
75
|
|
|
'type' => $this->tinyInteger(3)->unsigned()->notNull()->defaultValue(0)->comment('Type'), |
76
|
|
|
'source' => $this->varchar(255)->notNull()->defaultValue('')->collate('utf8_unicode_ci')->comment('Source'), |
77
|
|
|
], $tableOptions); |
78
|
|
|
} |
79
|
|
|
$this->addPrimaryKey('user_guid_pk', User::tableName(), 'guid'); |
80
|
|
|
$this->createIndex('user_id_unique', User::tableName(), 'id', true); |
81
|
|
|
$this->createIndex('user_auth_key_normal', User::tableName(), 'auth_key'); |
82
|
|
|
$this->createIndex('user_access_token_normal', User::tableName(), 'access_token'); |
83
|
|
|
$this->createIndex('user_password_reset_token_normal', User::tableName(), 'password_reset_token'); |
84
|
|
|
$this->createIndex('user_created_at_normal', User::tableName(), 'created_at'); |
85
|
|
|
$this->createIndex('user_status_normal', User::tableName(), 'status'); |
86
|
|
|
$this->createIndex('user_type_normal', User::tableName(), 'type'); |
87
|
|
|
$this->createIndex('user_source_normal', User::tableName(), 'source'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function down() |
91
|
|
|
{ |
92
|
|
|
$this->dropTable(User::tableName()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/* |
96
|
|
|
// Use safeUp/safeDown to run migration code within a transaction |
97
|
|
|
public function safeUp() |
98
|
|
|
{ |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function safeDown() |
102
|
|
|
{ |
103
|
|
|
} |
104
|
|
|
*/ |
105
|
|
|
} |
106
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.