CreateRolePermission::change()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
/**
6
 * Class CreateRolePermission
7
 */
8
class CreateRolePermission extends AbstractMigration
9
{
10
    /**
11
     * Create 'role_permission' table in database.
12
     * 'role_id' with 'permission_id' creates unique index.
13
     */
14
    public function change()
15
    {
16
        $rolePermissionTable = $this->table('role_permission', ['signed' => false]);
17
18
        $rolePermissionTable->addColumn('role_id', 'integer', ['signed' => false])
19
            ->addColumn('permission_id', 'integer', ['signed' => false])
20
            ->addColumn('created_at', 'datetime')
21
            ->addIndex(['role_id', 'permission_id'], ['name' => 'idx_role_permission_unique', 'unique' => true])
22
            ->addForeignKey('role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_role'])
23
            ->addForeignKey('permission_id', 'permission', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_permission'])
24
            ->create();
25
    }
26
}
27