Musings of a startup founder

Musings of a startup founder


Chris Duell, co-founder @ elev.io

Chris Duell
Author

CEO & Co-founder of elev.io

Share


elevio

Twitter


Protect or disable laravel artisan commands in production

While working on a product at VentureCraft, I wanted to make sure that there was no way I could accidentally screw myself over by running something like migrate…

Chris DuellChris Duell

While working on a product at VentureCraft, I wanted to make sure that there was no way I could accidentally screw myself over by running something like migrate:refresh in production. I put up a teaser on twitter which got some good attention so I thought I’d share the nasty code I used to achieve this.

The tweet:

Adding a confirmation before any artisan calls when in production, will save my ass no doubt #laravel pic.twitter.com/dZk6syeusF

— Chris Duell (@duellsy) April 4, 2014

The code:

At this stage, all I’m doing is adding a snippet of code to the top of my app/artisan.php file, which performs the check. At a later stage I planned on moving this to a package so I can use it in other projects, however I received the following tweet from Taylor which hopefully will make that redundant and he’ll just build it into the core (a touch more elegantly I’m sure):

@duellsy i should probably just bake that into the framework honestly

— Taylor Otwell (@taylorotwell) April 4, 2014

What’s ore, in the package I’d planned on allowing to pick and choose which commands are protected in which environment based on a config file, the following hopefully will take care of that too:

@duellsy at least for those destructive type actions on migrations

— Taylor Otwell (@taylorotwell) April 4, 2014

Update

Stoked to see that this has indeed been added into the core, as a trait you can add to your own commands

You’re welcome #laravel community :)http://t.co/TvLbGX4zVD This lead to > https://t.co/Ie4CxJeBoU

— Chris Duell (@duellsy) May 18, 2014

Chris Duell
Author

Chris Duell

CEO & Co-founder of elev.io

Comments