Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #459 from OpenSRP/issue458
Browse files Browse the repository at this point in the history
View configuration setup script add postgres support
  • Loading branch information
githengi authored Jun 14, 2018
2 parents 11e319b + ae84e46 commit 6d072dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 13 additions & 0 deletions assets/tbreach_default_view_configs/README.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
This folder contains the default view configuration json files as deployed with this Release Version of TB Reach as well as the Shell Script to populate the db with them.

The script works with both postgres and couchdb.

For couchDb
Make sure you have set up couch database on this machine and that couch is accessible via port 5894 (You can modify the script if you use a different port)
Run the command below:

./setup_view_configs.sh -d <database name> (e.g. ./setup_view_configs.sh -d opensrp_tbreach)

For Postgres

You must specify the parameter -t with value postgres. The default is couchdb
Make sure you have set up postgres database on this machine and that postgres is accessible via port 5432 (You can modify the script if you use a different port)
Run the command below:

./setup_view_configs.sh -t postgres -u <postgres_user> -pwd <postgres _user_password> -d opensrp -d <database name> (e.g. ./setup_view_configs.sh -t postgres -u opensrp_admin -pwd admin -d opensrp_tbreach)

Run ./setup_view_configs.sh --help to get a list of available options

Specify (Optional) database type like ./setup_view_configs.sh -t postgres

Specify (Optional) a database name like ./setup_view_configs.sh -d <database name>

Expand Down
18 changes: 15 additions & 3 deletions assets/tbreach_default_view_configs/setup_view_configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ PASSWORD=0
CONFIG_FOLDER=.
count="$#"
PROTO=0
TYPE='couchdb'


if [ "$1" == "--help" ]
then
echo -e "Specify (Optional) database type like \033[33m./setup_view_configs.sh -t postgres \033[0m"
echo -e "Specify (Optional) a database name like \033[33m./setup_view_configs.sh -d <database name> \033[0m"
echo -e "Specify (Optional) a host like \033[33m ./setup_view_configs.sh -h <hostname>\033[0m"
echo -e "Specify (Optional) a port name like \033[33m ./setup_view_configs.sh -p <port>\033[0m"
Expand All @@ -34,6 +36,10 @@ else
#set the params
for var in "$@"
do
if [ $varPrev == "-t" ];then
TYPE="$var"
fi

if [ $varPrev == "-d" ];then
DATABASE="$var"
fi
Expand Down Expand Up @@ -69,7 +75,8 @@ else

echo -e "\033[;32m Connecting to host \033[1;37m$HOST ...\033[0m"
echo -e "\033[;32m Connecting on port \033[0m$PORT"
echo -e "\033[;32m Couch Database specified \033[0m$DATABASE"
echo -e "\033[;32m Database specified \033[0m$TYPE"
echo -e "\033[;32m Database specified \033[0m$DATABASE"

if [ $CONFIG_FOLDER == "." ]; then
echo -e "\033[;32m View Configuration folder supplied \033[0m $(pwd)"
Expand Down Expand Up @@ -107,8 +114,13 @@ else


if [ $PASSWORD != 0 ]; then

curl -H 'Content-Type: application/json' -vX POST $PROTO://$USERNAME:$PASSWORD@$HOST:$PORT/$DATABASE -d @$f
if [ $TYPE = 'couchdb' ]; then
curl -H 'Content-Type: application/json' -vX POST $PROTO://$USERNAME:$PASSWORD@$HOST:$PORT/$DATABASE -d @$f
else
jsonString=$(sed "s/'/''/g" < $f)
view_id=$(PGPASSWORD=$PASSWORD psql -qtAX -U $USERNAME -h $HOST -d $DATABASE -c "INSERT INTO core.view_configuration(json) VALUES('$jsonString');SELECT currval('core.\"view_configuration_id_seq\"');")
PGPASSWORD=$PASSWORD psql -U $USERNAME -h $HOST -d $DATABASE -c "INSERT INTO core.view_configuration_metadata(view_configuration_id,document_id,identifier,server_version) SELECT $view_id,json->>'_id',json->>'identifier',(json->>'serverVersion')::BIGINT FROM core.view_configuration WHERE id=$view_id"
fi
else

curl -H 'Content-Type: application/json' -vX POST $PROTO://$USERNAME@$HOST:$PORT/$DATABASE -d @$f
Expand Down

0 comments on commit 6d072dc

Please sign in to comment.