forked from opencrvs/opencrvs-farajaland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear-all-data.sh
executable file
·70 lines (62 loc) · 2.62 KB
/
clear-all-data.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
65
66
67
68
69
70
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# OpenCRVS is also distributed under the terms of the Civil Registration
# & Healthcare Disclaimer located at http://opencrvs.org/license.
#
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
print_usage_and_exit () {
echo 'Usage: ./clear-all-data.sh --path_to_core=XXX'
echo "This script clears all OpenCRVS data locally. To run it you must pass the directory path to opencrvs-core."
echo "cd into opencrvs-core and run the command pwd to get this value."
echo " --path_to_core must be subitted. This is the path to your opencrvs-core directory with no trailing slash. E.G. /home/root/Documents/opencrvs-core"
exit 1
}
for i in "$@"; do
case $i in
--path_to_core=*)
path_to_core="${i#*=}"
shift
;;
-*|--*)
echo "Unknown option $i"
exit 1
;;
*)
;;
esac
done
if [ -z $path_to_core ]; then
echo "MISSING OR INCORRECT PARAMETER: --path_to_core"
echo
print_usage_and_exit
fi
# It's fine if these fail as it might be that the databases do not exist at this point
docker run --rm --network=opencrvs_default mongo:4.4 mongo --host mongo1 --eval "\
db.getSiblingDB('hearth-dev').dropDatabase();\
db.getSiblingDB('openhim-dev').dropDatabase();\
db.getSiblingDB('user-mgnt').dropDatabase();\
db.getSiblingDB('application-config').dropDatabase();\
db.getSiblingDB('metrics').dropDatabase();\
db.getSiblingDB('config').dropDatabase();\
db.getSiblingDB('performance').dropDatabase();\
db.getSiblingDB('webhooks').dropDatabase();"
docker run --rm --network=opencrvs_default appropriate/curl curl -XDELETE 'http://elasticsearch:9200/*' -v
docker run --rm --network=opencrvs_default appropriate/curl curl -X POST 'http://influxdb:8086/query?db=ocrvs' --data-urlencode "q=DROP SERIES FROM /.*/" -v
PATH_TO_MINIO_DIR="$path_to_core/data/minio/ocrvs"
# Clear Minio Data
if [ -d $PATH_TO_MINIO_DIR ] ; then
# Locally, as this script is called from the country config repo, the path to core is unknown
# So we delete the data from the running shared volume location
docker exec opencrvs_minio_1 rm -rf /data/minio/ocrvs
docker exec opencrvs_minio_1 mkdir -p /data/minio/ocrvs
echo "**** Removed minio data ****"
fi
echo "Running migrations"
echo
yarn --cwd="$path_to_core/packages/migration" start
echo
echo "Restarting openhim for the db changes to take effect"
echo
docker restart `docker ps --format "{{.Names}}" | grep openhim-core`