Skip to content

Instantly share code, notes, and snippets.

@dhruvbaldawa
Created September 20, 2012 08:20
Show Gist options
  • Save dhruvbaldawa/3754646 to your computer and use it in GitHub Desktop.
Save dhruvbaldawa/3754646 to your computer and use it in GitHub Desktop.
Bash script for automating some of django database cleanup
#### I am no Bash expert, I just googled and put this script together
#### Be free to fork and post updates to this gist
#### Also, you can change the username and email below for the django superuser
DEFAULT_USER="admin"
DEFAULT_EMAIL="admin@mail.com"
DEFAULT_PASS="pass"
function usage
{
echo "usage: $0 [-r | --runserver]"
}
runserver=
while [ "$1" != "" ]; do
case $1 in
-r | --runserver ) runserver=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
######## MAIN CLEAN #########
rm website.db
python manage.py syncdb --noinput
python manage.py migrate
### Create super-user
echo "from django.contrib.auth.models import User; User.objects.create_superuser('$DEFAULT_USER', '$DEFAULT_EMAIL', '$DEFAULT_PASS')" | python manage.py shell --plain
######## OPTIONAL RUNSERVER ########
if [ "$runserver" = "1" ]; then
python manage.py runserver
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment