1

I have installed an extension for Yii2 dektrium/yii2-user using composer using it's "require" section. This extension contains migrations for database. Is it possible to apply migrations from this extension using console syntax not like this:

php yii migrate --migrationPath=@dektrium/yii2-user/migrations

but run all migrations automatically by using a simple command like:

php yii migrate

Is it possible to tell composer where the concrete extension contains it's migrations?

2
  • yii migrate only take into consideration the migrations you have in your console/migrations folder
    – user5201742
    Mar 3, 2016 at 18:49
  • i found better solution that i had describe below. thanks!
    – bfday
    Mar 5, 2016 at 12:08

3 Answers 3

3

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).

1

I found only one good solution - Install yii2 extension https://github.com/dmstr/yii2-migrate-command

Now i can easily use command "php yii migrate" and don't worry that someone from my team doesn't apply required migrations.

Thanks others for help! If u find more appropriate solutions, please share =)

0

Yii2: Allow Migrate From Multiple Path

3
  • I would upvote your answer if you wouldn't just have posted a link! This is now how SO works. Consider that the link gets broken at some time. Then your answer is useless.
    – robsch
    May 11, 2017 at 11:18
  • @robsch when the link brakes, you can find it in the wayback machine - web.archive.org :) Nov 15, 2018 at 14:29
  • How to answer: Provide context for links - Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.
    – robsch
    Nov 15, 2018 at 15:12

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.