Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

A Laravel package to rebuild the database

Original – by Freek Van der Herten – 2 minute read

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.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "A Laravel package to rebuild the database"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.