Running Laravel Migrations on Heroku

Running Laravel Migrations on Heroku

   Leave a comment   
http://bit.ly/2lPOSZp

Migrations are a really handy was of making database changes, be it schema or data, and keeping it in sync across multiple locations. They are however much more useful when automatic, so when they are needed to be run, they run. This helps prevent errors when you forget to run the migrations for instance.

When using platforms like Heroku and tools like Composer, this becomes very easy.

All that’s needed is to add the php artisan migrate --force command (–force is needed because they are run on the production) into the post-install-cmd section of your composer.json. Your entire scripts section will look something like the following:

"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "php artisan optimize",
        "php artisan migrate --force",
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize"
    ]
},

Photo by NATS Press Office

˜

Leave a Reply

Your email address will not be published. Required fields are marked *