Skip to content

Instantly share code, notes, and snippets.

@admench
Created December 2, 2023 10:50
Show Gist options
  • Save admench/528f5275dd6249ce5cb981ccee553f75 to your computer and use it in GitHub Desktop.
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
## ===================================================================
## 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