1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHP permission handling library |
4
|
|
|
* @author Tao <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
use Migrations\AbstractMigration; |
7
|
|
|
use Cake\Core\Configure; |
8
|
|
|
|
9
|
|
|
class CreatePermissionTables extends AbstractMigration |
10
|
|
|
{ |
11
|
|
|
public function change() |
12
|
|
|
{ |
13
|
|
|
//creates permissions table |
14
|
|
|
$table = $this->table(Configure::read('Permission.tableNameMap.permissions') ?: 'permissions'); |
15
|
|
|
$table->addColumn('name', 'string', [ |
16
|
|
|
'default' => null, |
17
|
|
|
'limit' => 255, |
18
|
|
|
'null' => false, |
19
|
|
|
]); |
20
|
|
|
$table->addColumn('slug', 'text', [ |
21
|
|
|
'default' => null, |
22
|
|
|
'null' => false, |
23
|
|
|
]); |
24
|
|
|
$table->addColumn('created', 'datetime', [ |
25
|
|
|
'default' => null, |
26
|
|
|
'null' => false, |
27
|
|
|
]); |
28
|
|
|
$table->addColumn('modified', 'datetime', [ |
29
|
|
|
'default' => null, |
30
|
|
|
'null' => false, |
31
|
|
|
]); |
32
|
|
|
$table->create(); |
33
|
|
|
|
34
|
|
|
//creates roles table |
35
|
|
|
$table = $this->table(Configure::read('Permission.tableNameMap.roles') ?: 'roles'); |
36
|
|
|
$table->addColumn('name', 'string', [ |
37
|
|
|
'default' => null, |
38
|
|
|
'limit' => 255, |
39
|
|
|
'null' => false, |
40
|
|
|
]); |
41
|
|
|
$table->addColumn('slug', 'text', [ |
42
|
|
|
'default' => null, |
43
|
|
|
'null' => false, |
44
|
|
|
]); |
45
|
|
|
$table->addColumn('created', 'datetime', [ |
46
|
|
|
'default' => null, |
47
|
|
|
'null' => false, |
48
|
|
|
]); |
49
|
|
|
$table->addColumn('modified', 'datetime', [ |
50
|
|
|
'default' => null, |
51
|
|
|
'null' => false, |
52
|
|
|
]); |
53
|
|
|
$table->create(); |
54
|
|
|
|
55
|
|
|
//creates user_roles table |
56
|
|
|
$table = $this->table(Configure::read('Permission.tableNameMap.users_roles') ?: 'users_roles', [ |
57
|
|
|
'id' => false |
58
|
|
|
]); |
59
|
|
|
$table->addColumn('user_id', 'integer', [ |
60
|
|
|
'default' => null, |
61
|
|
|
'null' => false, |
62
|
|
|
]); |
63
|
|
|
$table->addColumn('role_id', 'integer', [ |
64
|
|
|
'default' => null, |
65
|
|
|
'null' => false, |
66
|
|
|
]); |
67
|
|
|
$table->addPrimaryKey(['user_id', 'role_id']); |
68
|
|
|
$table->create(); |
69
|
|
|
|
70
|
|
|
//creates roles_permissions table |
71
|
|
|
$table = $this->table(Configure::read('Permission.tableNameMap.roles_permissions') ?: 'roles_permissions', [ |
72
|
|
|
'id' => false |
73
|
|
|
]); |
74
|
|
|
$table->addColumn('role_id', 'integer', [ |
75
|
|
|
'default' => null, |
76
|
|
|
'null' => false, |
77
|
|
|
]); |
78
|
|
|
$table->addColumn('permission_id', 'integer', [ |
79
|
|
|
'default' => null, |
80
|
|
|
'null' => false, |
81
|
|
|
]); |
82
|
|
|
$table->addPrimaryKey(['role_id', 'permission_id']); |
83
|
|
|
$table->create(); |
84
|
|
|
} |
85
|
|
|
} |