Launching primary RBAC migrations as part of regular application migration

I am creating a product based on the Yii2 extended template.

As part of this product and its future deployments, I am trying to automatically create authorization-related tables in a regular Yii2 migration.

For example, when an end user installs a product and runs the regular Yii migration commands, it must have fully functional user management and authorization.

For authorization, the Yii2 RBAC documentation page indicates that 4 tables are required (auth_ *). The documentation states that they were created by performing the following migration:

yii migrate --migrationPath=@yii /rbac/migrations

I would like to compensate for this additional nuisance for the end user by running a specific migration code for him within the regular migration, which will be stored in common/migrations .

Any simple solution for this?

+6
source share
3 answers

I created a migrate.sh file where I placed my migration commands that I need to run. This allows me to move from multiple places at once. It's quite simple, look here: https://github.com/Mihai-P/yii2-app-advanced/blob/master/migrate.sh

Instead of running ./yii migrate/up I just ran sh migrate.sh , which will update everything from anywhere.

Fact point: you should not stick to exactly what Yii gave you. This is just a template for you. Insert it, change it, do it yourself.

+4
source

Try adding to console / config / main.php:

 'controllerMap' => [ 'migrate' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => [ '@console/migrations', '@yii/rbac/migrations', ] ] ], 
+1
source

Another approach (without using the * .sh file) is to copy the rbac_init migration to the migration folder:

 cp vendor/yiisoft/yii2/rbac/migrations/m???????_rbac_init.php console/migrations/ 

Now, when you run php yii migrate , it will enable rbac_init migration.

0
source

Source: https://habr.com/ru/post/983615/


All Articles