A Laravel package to rebuild the database
Out of the box Laravel comes with a few commands to migrate the database. One of them is migrate:refresh
. That one will first run the down
-steps for all your migrations and then run all the up
steps. After that process your database should have the same structure as specified in your migrations.
But what if your migrations don't have a down
-step? Because I seldom have to revert a migration in my recent projects I haven't bothered with coding up the down
steps. And without those down
steps running migrate:refresh
will result in errors, or worse, tears.
I've created a little package that contains a command to quickly nuke all the tables in the database, run all migrations and all seeders. It will not use the down
steps of the migrations but will simple use the output of the SHOW TABLES
query to knock down all tables.
Once the package is installed this is how you can build up your database again:
php artisan migrate:fresh
Need to run the seeds as well? No problem!
php artisan migrate:fresh --seed
The package works on MySQL, PostgreSQL and SQLite databases. If you need to perform some extra steps right before or right after the tables are dropped, you can hook into these events.
This this all sound good to you? Then check out the package on GitHub. On our company site you'll find a list of Laravel packages we've previously made.
What are your thoughts on "A Laravel package to rebuild the database"?