forked from gpii-ops/gpii-dataloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadData.sh
More file actions
executable file
·49 lines (38 loc) · 1.04 KB
/
Copy pathloadData.sh
File metadata and controls
executable file
·49 lines (38 loc) · 1.04 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
STATIC_DATA_DIR=${STATIC_DATA_DIR:-/home/node/universal/testData/dbData}
BUILD_DATA_DIR=${BUILD_DATA_DIR:-/home/node/universal/build/dbData}
log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1"
}
loadData() {
log "Loading data from $1"
for file in $1/*.json; do
log "Submitting $file"
curl -H 'Content-Type: application/json' -X POST "$COUCHDB_URL/_bulk_docs" -d @- <<CURL_DATA
{"docs": $(cat $file)}
CURL_DATA
if [ $? -ne 0 ]; then
log "Error submitting $file. Terminating."
exit 1
fi
done
log "Finished loading data from $1"
}
if [ -z "$COUCHDB_URL" ]; then
echo "COUCHDB_URL environment variable must be defined"
exit 1
fi
log "Starting"
if [ ! -z "$CLEAR_INDEX" ]; then
log "Deleting database at $COUCHDB_URL"
if ! curl -fsS -X DELETE "$COUCHDB_URL"; then
log "Error deleting database"
fi
fi
log "Creating database at $COUCHDB_URL"
if ! curl -fsS -X PUT "$COUCHDB_URL"; then
log "Database already exists at $COUCHDB_URL"
fi
# Submit data
loadData $STATIC_DATA_DIR
loadData $BUILD_DATA_DIR