Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid rbac migration m180523_151638_rbac_updates_indexes_without_prefix #17685

Closed
rvkulikov opened this issue Nov 25, 2019 · 3 comments
Closed
Labels
Milestone

Comments

@rvkulikov
Copy link
Contributor

rvkulikov commented Nov 25, 2019

What steps will reproduce the problem?

(tl;dr):
Look at the following lines:

  1. This one is good
    $this->db = $authManager->db;
  2. This is good too
  3. This is bad
    public function up()
    {
    $authManager = $this->getAuthManager();
    $this->dropIndex('auth_assignment_user_id_idx', $authManager->assignmentTable);
    $this->createIndex('{{%idx-auth_assignment-user_id}}', $authManager->assignmentTable, 'user_id');
    $this->dropIndex('idx-auth_item-type', $authManager->itemTable);
    $this->createIndex('{{%idx-auth_item-type}}', $authManager->itemTable, 'type');
    }

Third migration uses default db component (which may be different from authManager's db component). And if you use 2 db components, and authManager (DbManager) uses non-default db component, then third migration will just fail (it is good fortune that it just drops some indexes).

Please tell if it's not clear how to reproduce the problem and I'll write more details.

@rvkulikov
Copy link
Contributor Author

rvkulikov commented Nov 25, 2019

The workaround is obvious:

~/app/config/main.php

//...
    'container' => [
        'definitions' => [
            'm180523_151638_rbac_updates_indexes_without_prefix' => [
                'class' => 'm180523_151638_rbac_updates_indexes_without_prefix',
                'db' => 'proper_db_component'
            ],
        ]
    ],
//...

But I think it's not good. It's better to fix migration than to override migration's db component in every app which uses non-default db component.

@rvkulikov rvkulikov changed the title Invalid migration m180523_151638_rbac_updates_indexes_without_prefix Invalid rbac migration m180523_151638_rbac_updates_indexes_without_prefix Nov 25, 2019
@samdark samdark added this to the 2.0.31 milestone Nov 25, 2019
@samdark samdark added the type:bug Bug label Nov 25, 2019
@samdark
Copy link
Member

samdark commented Nov 25, 2019

@rvkulikov do you want to prepare a pull request?

@rvkulikov
Copy link
Contributor Author

@samdark OK.

rvkulikov added a commit to rvkulikov/yii2 that referenced this issue Nov 29, 2019
samdark added a commit that referenced this issue Nov 29, 2019
* Bug #17685: up and down methods now using proper "db" component

* Bug #17685: added message to changelog

* Update CHANGELOG.md
@samdark samdark closed this as completed Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants