Completed
Push — master ( 025c5a...9e6d5a )
by Alexander
13:30
created

up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
use yii\base\InvalidConfigException;
9
use yii\db\Migration;
10
use yii\rbac\DbManager;
11
12
/**
13
 * Updates indexes without a prefix.
14
 *
15
 * @see https://github.com/yiisoft/yii2/pull/15548
16
 *
17
 * @author Sergey Gonimar <[email protected]>
18
 * @since 2.0.16
19
 */
20
class m180523_151638_rbac_updates_indexes_without_prefix extends Migration
21
{
22
    /**
23
     * @throws yii\base\InvalidConfigException
24
     * @return DbManager
25
     */
26
    protected function getAuthManager()
27
    {
28
        $authManager = Yii::$app->getAuthManager();
29
        if (!$authManager instanceof DbManager) {
30
            throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.');
31
        }
32
33
        return $authManager;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function up()
40
    {
41
        $authManager = $this->getAuthManager();
42
43
        $this->dropIndex('auth_assignment_user_id_idx', $authManager->assignmentTable);
44
        $this->createIndex('{{%idx-auth_assignment-user_id}}', $authManager->assignmentTable, 'user_id');
45
46
        $this->dropIndex('idx-auth_item-type', $authManager->itemTable);
47
        $this->createIndex('{{%idx-auth_item-type}}', $authManager->itemTable, 'type');
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function down()
54
    {
55
        $authManager = $this->getAuthManager();
56
57
        $this->dropIndex('{{%idx-auth_assignment-user_id}}', $authManager->assignmentTable);
58
        $this->createIndex('auth_assignment_user_id_idx', $authManager->assignmentTable, 'user_id');
59
60
61
        $this->dropIndex('{{%idx-auth_item-type}}', $authManager->assignmentTable);
62
        $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');
63
    }
64
}
65