Skip to content

Instantly share code, notes, and snippets.

@geekforbrains
Last active March 10, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekforbrains/6f0929c845ce52ff29b7 to your computer and use it in GitHub Desktop.
Save geekforbrains/6f0929c845ce52ff29b7 to your computer and use it in GitHub Desktop.
A simple tool for clearing and rebuilding database and migrations in Django during dev
#!/usr/bin/env bash
echo "Database name:"
read db_name
# Delete migration folders
find apps -iname 'migrations*' -exec rm -rf {} \; > /dev/null 2>&1
# Re-create empty migration folder with __init__ file
for d in apps/*; do
if [ -d $d ]; then
mkdir -p $d/migrations
touch $d/migrations/__init__.py
fi
done
# Re-create db
dropdb $db_name
createdb $db_name
# Build and run migrations
./manage.py makemigrations
./manage.py migrate
# Setup super user
echo "Superuser [root] password:"
./manage.py createsuperuser --username root --email root@localhost.local
echo ""
echo "Smell that? Its fresh migrations."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment