When working on a Laravel project I often switch between my local MySQL database (which has minimal seeded data) and an external staging database (filled with representative, production-like data). I switch by commenting out the connection details in my .env
file.
For my local database, I often run php artisan migrate:refresh --seed
to test new models and relations. But I never want to run this command (by accident, when I forget to switch to my local db) on the staging database.
Is there a pre-execution function (or something similar) for the migrate
command I can implement to first check if my DB_HOST
has some value, and stop the execution if I detect that the staging environment is chosen?
Note: Disabling write permissions for my user on the staging database is not an option since I test inserts/deletes on that database.