I am building a product that is based on the Yii2 advanced template.
As part of this product and its future deployments, I am trying to automatically create the tables related to Authorization in a regular Yii2 migration.
E.g, when the end user installs the product and runs the regular Yii migration commands he should have a fully functional user management AND authorization active.
For authorization to work, the Yii2 RBAC documentation page states that 4 tables are needed (auth_*). The documentation states that they are created by running the following migration:
yii migrate --migrationPath=@yii/rbac/migrations
I'd like to offset this extra hassle from the end user by running this specific migration code for him inside a regular migration that will be stored in common/migrations
.
Any easy solution for this?
In my previous post I discussed the need to run database migrations as part of an application deployment, so that the database migrations are applied before the new application code starts running. This allows zero-downtime deployments, and ensures that the new application code doesn't have to work against old versions of the database.
With the proposed solution (and careful database schema design!) you can perform rolling updates of your application that includes database migrations. The problem is very common—the new version of your app uses a slightly different database schema to the previous version.
If you created the initial migration when the database already exists, the database creation code is generated but it doesn't have to run because the database already matches the data model.
After you have run a migration plan in your assistant (like selecting a cloud instance and entities to migrate), re-run the app migration using the following URL: rest/migration/latest/app-migration/rerun/<planId> . This operation can be repeated multiple times as required.
I have created a migrate.sh file where I put my migration commands that I need to run. This allows me to migrate from multiple places in the same time. It is quite simple, take a look here: https://github.com/Mihai-P/yii2-app-advanced/blob/master/migrate.sh
Instead of running ./yii migrate/up
i just run sh migrate.sh
that will update everything from any place.
The actual point of this is: you do not have to stick to exactly what Yii gave you. That is just a template for you to build on. Fork it, modify it, make it your own.
Try to add in console/config/main.php:
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => [
'@console/migrations',
'@yii/rbac/migrations',
]
]
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With