Last active
March 10, 2016 23:15
-
-
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
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
#!/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 [email protected] | |
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