CreateUserRole   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

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