|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Phinx\Migration\AbstractMigration; |
|
4
|
|
|
|
|
5
|
|
|
class ModuleUsers extends AbstractMigration |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Change Method. |
|
9
|
|
|
* |
|
10
|
|
|
* Write your reversible migrations using this method. |
|
11
|
|
|
* |
|
12
|
|
|
* More information on writing migrations is available here: |
|
13
|
|
|
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class |
|
14
|
|
|
* |
|
15
|
|
|
* The following commands can be used in this method and Phinx will |
|
16
|
|
|
* automatically reverse them when rolling back: |
|
17
|
|
|
* |
|
18
|
|
|
* createTable |
|
19
|
|
|
* renameTable |
|
20
|
|
|
* addColumn |
|
21
|
|
|
* renameColumn |
|
22
|
|
|
* addIndex |
|
23
|
|
|
* addForeignKey |
|
24
|
|
|
* |
|
25
|
|
|
* Remember to call "create()" or "update()" and NOT "save()" when working |
|
26
|
|
|
* with the Table class. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function change() |
|
29
|
|
|
{ |
|
30
|
|
|
$users = $this->table('users'); |
|
31
|
|
|
$users |
|
32
|
|
|
->addColumn('login', 'string', ['length' => 255]) |
|
33
|
|
|
->addColumn('email', 'string', ['length' => 255, 'null' => true]) |
|
34
|
|
|
->addTimestamps('created', 'updated') |
|
35
|
|
|
->addColumn('status', 'string', ['length' => 32, 'default' => 'disabled']) |
|
36
|
|
|
->addIndex(['login'], ['unique' => true]) |
|
37
|
|
|
->addIndex(['email'], ['unique' => true]) |
|
38
|
|
|
->create(); |
|
39
|
|
|
|
|
40
|
|
|
$actions = $this->table('users_actions', ['id' => false, 'primary_key' => ['userId', 'code']]); |
|
41
|
|
|
$actions |
|
42
|
|
|
->addColumn('userId', 'integer') |
|
43
|
|
|
->addColumn('code', 'string', ['length' => 64]) |
|
44
|
|
|
->addColumn('action', 'string', ['length' => 64]) |
|
45
|
|
|
->addColumn('params', 'text') |
|
46
|
|
|
->addColumn('created', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'update' => '']) |
|
47
|
|
|
->addColumn('expired', 'timestamp', ['null' => true]) |
|
48
|
|
|
->addForeignKey('userId', $users, 'id', [ |
|
49
|
|
|
'delete' => 'CASCADE', |
|
50
|
|
|
'update' => 'CASCADE' |
|
51
|
|
|
]) |
|
52
|
|
|
->create(); |
|
53
|
|
|
|
|
54
|
|
|
$auth = $this->table('auth', ['id' => false, 'primary_key' => ['userId', 'provider']]); |
|
55
|
|
|
$auth |
|
56
|
|
|
->addColumn('userId', 'integer') |
|
57
|
|
|
->addColumn('provider', 'string', ['length' => 64]) |
|
58
|
|
|
->addColumn('foreignKey', 'string', ['length' => 255]) |
|
59
|
|
|
->addColumn('token', 'string', ['length' => 255]) |
|
60
|
|
|
->addColumn('tokenSecret', 'string', ['null' => true, 'length' => 255]) |
|
61
|
|
|
->addColumn('tokenType', 'string', ['length' => 64]) |
|
62
|
|
|
->addTimestamps('created', 'updated') |
|
63
|
|
|
->addColumn('expired', 'timestamp', ['null' => true]) |
|
64
|
|
|
->addForeignKey('userId', $users, 'id', [ |
|
65
|
|
|
'delete' => 'CASCADE', |
|
66
|
|
|
'update' => 'CASCADE' |
|
67
|
|
|
]) |
|
68
|
|
|
->create(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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.