-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate_db.sh
executable file
·42 lines (32 loc) · 1.08 KB
/
migrate_db.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
#!/bin/sh
prod=true
[ $# -gt 0 -a "$1" == -d ] && prod=false
if $prod; then
export DJANGO_SETTINGS_MODULE=datavis.settings.production
DJROOT=${DJROOT:-/var/django}
DJVIRT=${DJVIRT:-$DJROOT/virtualenv/django}
VAR_LIB_DIR=/var/lib/django
sudo chmod -R g+w /var/lib/django
sudo chmod -R g+w /var/log/django
else
DJVIRT=${DJVIRT:-$HOME/virtualenvs/django}
VAR_LIB_DIR=$(dirname $0)
fi
[ $VIRTUAL_ENV ] || source $DJVIRT/bin/activate
db_exists=false
# [ -f $VAR_LIB_DIR/db.sqlite3 ] && db_exists=true
sudo su - postgres -c "psql -lqt | cut -d \| -f 1 | grep -qw ncharts" && db_exists=true
if $db_exists; then
# Have to specify the ncharts app name in order to make its migrations
python3 manage.py makemigrations ncharts
python3 manage.py migrate ncharts
else
./create_pgdb.sh $*
python3 manage.py makemigrations
python3 manage.py makemigrations ncharts
# --fake-initial: mark the migration as having been already applied
python3 manage.py migrate --fake-initial ncharts
fi
if $prod; then
sudo chgrp apache /var/lib/django/db.sqlite3
fi