From ab32065e1d223d4a2769c3eab02165ad2e971661 Mon Sep 17 00:00:00 2001 From: Luis Bosque Date: Thu, 18 Feb 2016 15:13:15 +0100 Subject: [PATCH] Script to help to enable the extension in dev env --- scripts/create_extension_in_db.sh | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/create_extension_in_db.sh diff --git a/scripts/create_extension_in_db.sh b/scripts/create_extension_in_db.sh new file mode 100755 index 0000000..d7c4176 --- /dev/null +++ b/scripts/create_extension_in_db.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +TARGET_DB=$1 +PGUSER=${2:-postgres} +PYTHON_LIBRARY_NAME='cartodb_services' + +function usage { + echo "Usage: ${0} [dbuser]" +} + +[[ -z $TARGET_DB ]] && echo "Missing DB parameter" && usage && exit 1 + +python -c "import ${PYTHON_LIBRARY_NAME}" +if [[ $? != 0 ]] +then + echo "Missing ${PYTHON_LIBRARY_NAME} python library" + echo "Trying to install.." + cd server/lib/python/cartodb_services && sudo python setup.py install + python -c "import ${PYTHON_LIBRARY_NAME}" 2> /dev/null + if [[ $? != 0 ]] + then + echo "There are some problems with python library. Debug manually" + exit 1 + fi +fi + +CREATE_EXTENSION_COMMAND="CREATE EXTENSION IF NOT EXISTS" + +CDB_GEOCODER_EXTENSION_CREATE="${CREATE_EXTENSION_COMMAND} cdb_geocoder" +CDB_DATASERVICES_SERVER_CREATE="${CREATE_EXTENSION_COMMAND} cdb_dataservices_server" + +echo "* Creating extension cdb_geocoder" +psql -U ${PGUSER} -d ${TARGET_DB} -c "${CDB_GEOCODER_EXTENSION_CREATE}" +echo "* Creating extension cdb_dataservices_server" +psql -U ${PGUSER} -d ${TARGET_DB} -c "${CDB_DATASERVICES_SERVER_CREATE}"