问题描述:

I just installed Cartalyst's Sentry 2 in a Laravel 4 application but I found out that I have to run that package's migrations separately by specifying --package=cartalyst/sentry, which makes automatic deployment impossible.

Is there a way to run php artisan migrate and have it run Sentry's migrations as well?

网友答案:

What I usually do in a scenario like this is publish the package migrations though the command:

php artisan migrate:publish vendor/package

This copies the migration files from any given package to your migrations folder.

网友答案:

I created a composer script to replace php artisan migrate ...... The script runs my migrations and the vendor's migrations everything at once.

My composer scripts is

"scripts": {
    "migrate": [
        "php artisan migrate --env=$LARAVEL_ENV",
        "php artisan migrate --package=\"cartalyst/sentry\" --env=$LARAVEL_ENV",
        "php artisan migrate --package=\"mrjuliuss/syntara\" --env=$LARAVEL_ENV",
        "php artisan migrate --package=\"filmoteca/static-pages\" --env=$LARAVEL_ENV"
    ]
}

Then you can run the migration with LARAVEL_ENV=prod composer run-script migrate

To pass parameter to the script I use environment variables. In the previous example I set the environment variable LARAVEL_ENV to prod so the migration use the production database connection.

You can always create a alias in your local machine to short the command. For example alias migrate="LARAVEL_ENV=local composer run-script migrate"

I think this approach is good because when you are going to add a new package to your composer.json and this package has a migration you add the package and the package's migration in the same file. So, you do not forget add/remove the migration of a package.

This is a complete composer.json with the script

相关阅读:
Top