1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use inblank\activeuser\migrations\Migration; |
5
|
|
|
use yii\db\Schema; |
6
|
|
|
|
7
|
|
|
class m160523_164512_activeuser_init extends Migration |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
public function up() |
10
|
|
|
{ |
11
|
|
|
// Accounts |
12
|
|
|
$tab = self::tn(self::TAB_USERS); |
13
|
|
|
$this->createTable($tab, [ |
14
|
|
|
'id' => Schema::TYPE_PK, |
15
|
|
|
'status' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0', |
16
|
|
|
|
17
|
|
|
'email' => Schema::TYPE_STRING . "(200) NOT NULL DEFAULT ''", |
18
|
|
|
'pass_hash' => Schema::TYPE_STRING . "(60) NOT NULL DEFAULT ''", |
19
|
|
|
|
20
|
|
|
'name' => Schema::TYPE_STRING . "(200) NOT NULL DEFAULT ''", |
21
|
|
|
'gender' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0', |
22
|
|
|
'birth' => Schema::TYPE_DATE . " DEFAULT NULL", |
23
|
|
|
'avatar' => Schema::TYPE_STRING . "(45) NOT NULL DEFAULT ''", |
24
|
|
|
|
25
|
|
|
'access_token' => Schema::TYPE_STRING . "(40) DEFAULT NULL", |
26
|
|
|
'auth_key' => Schema::TYPE_STRING . "(40) DEFAULT NULL", |
27
|
|
|
|
28
|
|
|
'token' => Schema::TYPE_STRING . "(40) DEFAULT NULL", |
29
|
|
|
'token_created_at' => Schema::TYPE_INTEGER . " NOT NULL DEFAULT 0", |
30
|
|
|
|
31
|
|
|
'registered_at' => Schema::TYPE_DATETIME . ' DEFAULT NULL', |
32
|
|
|
], $this->tableOptions); |
33
|
|
|
$this->createIndex('unique_email', $tab, 'email', true); |
34
|
|
|
$this->createIndex('unique_access_token', $tab, 'access_token', true); |
35
|
|
|
$this->createIndex('unique_auth_key', $tab, 'auth_key', true); |
36
|
|
|
$this->createIndex('unique_token', $tab, 'token', true); |
37
|
|
|
|
38
|
|
|
// Accounts profiles |
39
|
|
|
$tab = self::tn(self::TAB_PROFILES); |
40
|
|
|
$this->createTable($tab, [ |
41
|
|
|
'user_id' => Schema::TYPE_PK, |
42
|
|
|
'site' => Schema::TYPE_STRING . "(255) NOT NULL DEFAULT ''", |
43
|
|
|
'location' => Schema::TYPE_STRING . "(255) NOT NULL DEFAULT ''", |
44
|
|
|
], $this->tableOptions); |
45
|
|
|
$this->addForeignKey( |
46
|
|
|
self::fk(self::TAB_PROFILES, self::TAB_USERS), |
47
|
|
|
$tab, 'user_id', |
48
|
|
|
self::tn(self::TAB_USERS), 'id', |
49
|
|
|
'CASCADE', 'RESTRICT' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function down() |
54
|
|
|
{ |
55
|
|
|
$tables = [ |
56
|
|
|
self::TAB_PROFILES, |
57
|
|
|
self::TAB_USERS, |
58
|
|
|
]; |
59
|
|
|
foreach ($tables as $table) { |
60
|
|
|
$this->dropTable(self::tn($table)); |
61
|
|
|
} |
62
|
|
|
return true; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.