Created
December 2, 2023 10:50
-
-
Save admench/528f5275dd6249ce5cb981ccee553f75 to your computer and use it in GitHub Desktop.
Database clear script - Remove database entirely, create new one and import from sql file, then run laravel migration and seed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## =================================================================== | |
## Database clear script | |
## Remove database entirely, create new one and import from sql file | |
## then run laravel migration and seed | |
## =================================================================== | |
# check if user passes two parameters | |
if [ $# -ne 3 ]; then | |
echo "Usage: $0 <db-name> <sql-file> <db-password>" | |
exit 1 | |
fi | |
# delete db | |
mysql -u root -p$3 -e "DROP DATABASE IF EXISTS $1" | |
# create db | |
mysql -u root -p$3 -e "CREATE DATABASE $1" | |
# import from sql | |
mysql -u root -p$3 $1 < $2 | |
# run migration | |
php artisan migrate | |
# run seed | |
php artisan db:seed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment