forked from Zipstack/unstract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_django_migrations.sh
More file actions
executable file
·49 lines (39 loc) · 1.15 KB
/
Copy pathcheck_django_migrations.sh
File metadata and controls
executable file
·49 lines (39 loc) · 1.15 KB
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
#! /bin/sh
script_dir=$(dirname "$(readlink -f "$BASH_SOURCE")")
cd $script_dir/../../backend
# Check Django default db connectivity.
# Use Python for cross-platform compatibility.
python3 << EOF
import os
import socket
import sys
import dotenv
dotenv.load_dotenv()
def _check_connectivity(host, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(2)
errno = s.connect_ex((host, port))
return errno
db_host = os.getenv("DB_HOST", "localhost")
db_port = int(os.getenv("DB_PORT", 5432))
errno = _check_connectivity(db_host, db_port)
if errno == 0:
print("Django default db ok:", os.strerror(errno))
sys.exit(0)
else:
print("Django default db error:", os.strerror(errno))
sys.exit(1)
EOF
if [ $? -ne 0 ]; then
echo ""
echo "Verify DB_HOST, DB_PORT settings for backend Django default db."
echo "If db is running in a container, add DB_HOST value to /etc/hosts."
echo ""
exit 1
fi
# Check Django migrations.
python3 manage.py makemigrations --check --dry-run --no-input
# ! IMPORTANT !
# Above command does not return error exit code
# on network error when connecting to db.
exit 0