forked from magnet-cl/django-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.sh
executable file
·51 lines (41 loc) · 1.02 KB
/
reset.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -e
function print_red() {
echo -e "\033[31m$1\033[39m"
}
RUNSERVER=false
while getopts "sh" OPTION
do
case $OPTION in
s)
echo "Start Server"
RUNSERVER=true
;;
?)
echo "fail"
exit
;;
esac
done
debug=$(python -c "from project.settings import DEBUG; print(DEBUG)")
dbname=$(python -c "from project.settings import LOCAL_DATABASES; print(LOCAL_DATABASES['default']['NAME'])")
if [ "$debug" != "True" ] ; then
print_red "DEBUG is not True."
exit 1
fi
echo "----------------------drop-database------------------------------"
set +e
drop_output=$(dropdb "$dbname" 2>&1)
drop_code=$?
set -e
echo "$drop_output"
# Fail if dropdb failed, except in case of "does not exist"
if [[ $drop_code -ne 0 && "$drop_output" != *" does not exist" ]]; then
exit $drop_code
fi
echo " create-database"
createdb "$dbname"
python manage.py migrate
if $RUNSERVER ; then
python manage.py runserver 0.0.0.0:8000 --nothreading
fi