|
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
|
|
|
namespace rhosocial\user\models\migrations; |
|
13
|
|
|
|
|
14
|
|
|
use rhosocial\user\migrations\Migration; |
|
15
|
|
|
use rhosocial\user\models\Username; |
|
16
|
|
|
use rhosocial\user\User; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class m170507_131103_createUsernameTable |
|
20
|
|
|
* @version 1.0 |
|
21
|
|
|
* @author vistart <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class m170507_131103_createUsernameTable extends Migration |
|
24
|
|
|
{ |
|
25
|
|
|
public function up() |
|
26
|
|
|
{ |
|
27
|
|
|
$tableOptions = null; |
|
|
|
|
|
|
28
|
|
|
if ($this->db->driverName == 'mysql') { |
|
29
|
|
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci |
|
30
|
|
|
$tableOptions = "CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB COMMENT='Username'"; |
|
31
|
|
|
$this->createTable(Username::tableName(), [ |
|
32
|
|
|
'guid' => $this->varbinary(16)->notNull()->comment('User GUID'), |
|
33
|
|
|
'content' => $this->varchar(32)->charset('utf8mb4')->collate('utf8mb4_unicode_ci')->defaultValue('')->notNull()->comment('Username'), |
|
34
|
|
|
'ip' => $this->varbinary(16)->defaultValue(0)->notNull()->comment('IP Address'), |
|
35
|
|
|
'ip_type' => $this->smallInteger()->defaultValue(4)->notNull()->comment('IP Address Type'), |
|
36
|
|
|
'created_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Created At'), |
|
37
|
|
|
'updated_at' => $this->dateTime()->notNull()->defaultValue('1970-01-01 00:00:00')->comment('Updated At'), |
|
38
|
|
|
], $tableOptions); |
|
39
|
|
|
} |
|
40
|
|
|
$this->addPrimaryKey('user_username_guid_pk', Username::tableName(), 'guid'); |
|
41
|
|
|
$this->addForeignKey('user_username_fk', Username::tableName(), 'guid', User::tableName(), 'guid', 'CASCADE', 'CASCADE'); |
|
42
|
|
|
$this->createIndex('username_unique', Username::tableName(), 'content', true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function down() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->dropTable(Username::tableName()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/* |
|
51
|
|
|
// Use safeUp/safeDown to run migration code within a transaction |
|
52
|
|
|
public function safeUp() |
|
53
|
|
|
{ |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function safeDown() |
|
57
|
|
|
{ |
|
58
|
|
|
} |
|
59
|
|
|
*/ |
|
60
|
|
|
} |
|
61
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.