-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-rebuild
executable file
·69 lines (60 loc) · 1.84 KB
/
db-rebuild
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# For copyright and license terms, see COPYRIGHT.rst (top level of repository)
# Repository: https://github.com/C3S/collecting_society_docker
#
#% Usage: ./db-rebuild [--ci] [--help]
#%
#% This script deletes and recreates the database and generates the demodata.
#%
#% Options:
#% --ci: stops the services before, starts the services detached afterwards
#% --help: display this help
# print usage
usage() {
[ "$*" ] && echo "$0: $*"
sed -n '/^#%/,/^$/s/^#% \{0,1\}//p' "$0"
exit 2
} 2>/dev/null
# get directories
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $ROOT_DIR
echo $ROOT_DIR
# get options
CI=false
for i in "$@"; do
if [ $i = "--ci" ]; then CI=true; continue; fi
if [ $i = "--help" ]; then usage 2>&1; fi
done
# print header
echo "====================================================================="
echo "====================================================================="
echo "= this script rebuilds the database of the project ="
echo "====================================================================="
echo `date +%Y-%m-%d:%H:%M:%S`
# stop docker containers
if $CI; then
echo -e "\n== stop docker containers"
docker compose stop
fi
# delete database
echo -e "\n== rebuild database"
if docker compose ps | grep "\-erpserver" | grep -v "\(Exit\|exited\)"; then
docker compose exec erpserver db-rebuild
EXITCODE=$1
else
docker compose run --rm erpserver db-rebuild
EXITCODE=$1
fi
if $CI; then
echo "exitcode: $EXITCODE"
fi
# start docker containers
if $CI; then
echo -e "\n== start docker containers"
docker compose up -d
fi
# print footer
echo `date +%Y-%m-%d:%H:%M:%S`
echo "====================================================================="
echo "====================================================================="
exit $EXITCODE