Passed
Branch master (c62005)
by ABDULMALIK
02:15
created

CreateRoleHierarchy   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 9
c 2
b 0
f 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 11 1
1
<?php
2
3
4
use Phinx\Migration\AbstractMigration;
5
6
class CreateRoleHierarchy extends AbstractMigration
7
{
8
    /**
9
     * Create 'role_hierarchy' table
10
     * 'parent_role_id' with 'child_role_id' creates unique index.
11
     */
12
    public function change()
13
    {
14
        $userRoleTable = $this->table('role_hierarchy', ['signed' => false]);
15
16
        $userRoleTable->addColumn('parent_role_id', 'integer', ['signed' => false])
17
            ->addColumn('child_role_id', 'integer', ['signed' => false])
18
            ->addColumn('created_at', 'datetime')
19
            ->addIndex(['parent_role_id', 'child_role_id'], ['name' => 'idx_role_hierarchy_unique', 'unique' => true])
20
            ->addForeignKey('parent_role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_hierarchy_parent'])
21
            ->addForeignKey('child_role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_hierarchy_child'])
22
            ->create();
23
    }
24
}
25