If you want to make this process automated, you can use scripts
property of composer
. For more information you can see https://getcomposer.org/doc/articles/scripts.md. In your case you can do your goal with something like this on composer.json
:
{
// Some codes are here
"scripts": {
"post-update-cmd": [
"php yii migrate --migrationPath=@dektrium/yii2-user/migrations"
],
"post-install-cmd": [
"php yii migrate --migrationPath=@dektrium/yii2-user/migrations"
]
},
// Some codes are here
}
I prefer to save all commands that must be run after install -or update- on a file (for example file named commands
) in the root of project, like this:
#!/usr/bin/env bash
./yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations
./yii migrate/up
./yii migrate/up --migrationPath=@app/modules/rules/migrations
./yii migrate/up --migrationPath=@app/modules/formsaz/migrations
./yii migrate/up --migrationPath=@app/modules/todo/migrations
./yii formsaz/rules/init
./yii husky/rules/init
and on composer.json
file put its name:
{
// Some codes are here
"scripts": {
"post-update-cmd": [
"sh commands"
],
"post-install-cmd": [
"sh commands"
]
},
// Some codes are here
}
So each time after composer install
or composer update
, all commands will be run (and it's useful on teamwork).