ModifyRolesAndPermissionsTableOptimizeIndexes   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 4 1
A revertIndexes() 0 4 1
A down() 0 4 1
A optimizeIndexes() 0 4 1
1
<?php
2
3
use Helldar\Roles\Support\Database\BaseMigration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class ModifyRolesAndPermissionsTableOptimizeIndexes extends BaseMigration
7
{
8
    public function up()
9
    {
10
        $this->optimizeIndexes($this->user_role, 'user_id');
11
        $this->optimizeIndexes($this->role_permission, 'role_id');
12
    }
13
14
    public function down()
15
    {
16
        $this->revertIndexes($this->user_role, 'user_id');
17
        $this->revertIndexes($this->role_permission, 'role_id');
18
    }
19
20
    protected function optimizeIndexes(string $table, string $first_key)
21
    {
22
        $this->table($table, function (Blueprint $table) use ($first_key) {
23
            $table->index([$first_key]);
24
        });
25
    }
26
27
    protected function revertIndexes(string $table, string $first_key)
28
    {
29
        $this->table($table, function (Blueprint $table) use ($first_key) {
30
            $table->dropIndex([$first_key]);
31
        });
32
    }
33
}
34