-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsql-to-json.sh
executable file
·64 lines (52 loc) · 1.6 KB
/
sql-to-json.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
#
# sql-to-json.sh
# Usage: ./sql-to-json.sh local/SQL_FILE OCL_ORG SOURCE_ID [qa|staging|production|demo]
#
# Where:
# SQL_FILE = name of OpenMRS sql file
# OCL_ORG = organization ID within OCL (default 'CIEL')
# SOURCE_ID = name of source within organization (default 'CIEL')
# OCL_ENV = demo, staging, or production (default 'staging')
# If FORCE_OLD_MODE=1 in environment, then output will be separate mapping & concepts
# If USE_GOLD_MAPPINGS=1 in environment, gold mappings will be required and used
#
# Loads the OpenMRS sql file into a database and then exports it to JSON
SQL_FILE="${1:-openmrs.sql.zip}"
OCL_ORG="${2:-CIEL}"
SOURCE_ID="${3:-CIEL}"
OCL_ENV="${4:-staging}"
FORCE_OLD_MODE="$FORCE_OLD_MODE"
USE_GOLD_MAPPINGS="${USE_GOLD_MAPPINGS:-0}"
if [ -z "$SQL_FILE" ]
then
echo "OpenMRS SQL file is required"
echo "Usage: $0 SQL_FILE [production|staging|demo|qa]"
exit 1
fi
while true; do
if [ "$(docker ps -a -f status=exited | grep python)" ]; then
# Shut down stack
docker compose down -v
# Return program flow to the `wait` line
break
else
# Check status every second
sleep 1
fi
done & # Run in the background
BACKGROUND_PID=$!
echo "Processing $SQL_FILE for $OCL_ENV"
# Start up our database
# SQL_FILE="$SQL_FILE" OCL_ORG="$OCL_ORG" SOURCE_ID="$SOURCE_ID" OCL_ENV="$OCL_ENV" FORCE_OLD_MODE="$FORCE_OLD_MODE"
export SQL_FILE
export OCL_ORG
export SOURCE_ID
export OCL_ENV
export FORCE_OLD_MODE
export USE_GOLD_MAPPINGS
docker compose up -d
docker compose logs -f python &
wait $BACKGROUND_PID # Wait for the `while true` loop to be broken
echo "Done."
exit 0