Skip to content

Instantly share code, notes, and snippets.

@hseritt
Created February 25, 2017 12:41
Show Gist options
  • Save hseritt/9893165bf4ea4435fe26926657e3564b to your computer and use it in GitHub Desktop.
Save hseritt/9893165bf4ea4435fe26926657e3564b to your computer and use it in GitHub Desktop.
A script to reset fully a Django app's db connections and re-migrate
#!/usr/bin/env bash
clear; reset;
./clear-pyc.sh
#sudo service mysql start
sudo service postgresql start
echo "Clearing database ..."
echo " SQLite3 ..."
rm -rf db.sqlite3
#echo " MySQL ..."
#mysql -u admin -padmin -e "drop database activotrack"
#mysql -u admin -padmin -e "create database activotrack"
echo " Postgresql ..."
sudo -iu postgres dropdb activotrack
sudo -iu postgres createdb -O admin activotrack
echo "Clearing old content ..."
rm -rf static/content
echo "Clearing log files ..."
rm -rf logs/*
# echo "Clearing old migration data ..."
# rm -rf apps/activities/migrations
# rm -rf apps/articles/migrations
# rm -rf apps/business/migrations
# rm -rf apps/cases/migrations
# rm -rf apps/common/migrations
# rm -rf apps/contacts/migrations
# rm -rf apps/issues/migrations
echo "Creating migrations for apps ..."
./manage.py makemigrations common
./manage.py makemigrations activities
./manage.py makemigrations articles
./manage.py makemigrations business
./manage.py makemigrations contacts
./manage.py makemigrations issues
./manage.py makemigrations cases
echo "Running migration scripts ..."
./manage.py migrate
echo "Creating the superuser ..."
./manage.py createsuperuser --username admin --email admin@localhost --noinput
echo "Running bootstrap data scripts ..."
scripts/set_admin_pw.py
scripts/bootstrap_scripts.py
scripts/add_mock_data.py
#./runtests.sh
echo "Reset script finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment