A command to Drop/ Recreate database(s) in laravel.
Like php artisan migrate:fresh, is there any command which deletes and recreates database as well as the tables?
If not then what is the best way to create a custom command which will follow these steps to make setup/ testing easier.
1- Check the environment and read db-name from .env/ .env.test
2- Check if db exists
3- Delete if exists
4- Recreate db with same name
5- php artisan migrate
6- php artisan db:seed
So in the end we can add our command to composer.json in scripts which would look somethin like
"reset-test-db --env=test"
@shahzaibtariqbutt I don't think there is a built-in command for that already.
- You need to create the command.
- Add to the
composer.json
"scripts": {
"reset-db": [
"php artisan reset:db --env=test"
]
}
Now you can run the command from two different ways:
composer reset-db
Or
php artisan reset:db --env=testing
You might also need to store root database password
Please or to participate in this conversation.