diff --git a/build/itag-database/installDB.sh b/build/itag-database/installDB.sh index 2f71c03..958d63b 100755 --- a/build/itag-database/installDB.sh +++ b/build/itag-database/installDB.sh @@ -8,8 +8,8 @@ err_report() { } trap 'err_report $LINENO' ERR -PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/00_itag_extensions.sql > /dev/null 2>&1 -PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/01_itag_functions.sql > /dev/null 2>&1 -PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/01_tamn.sql > /dev/null 2>&1 -PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/02_itag_model.sql > /dev/null 2>&1 +PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/00_itag_extensions.sql +PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/01_itag_functions.sql +PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/01_tamn.sql +PGPASSWORD=${POSTGRES_PASSWORD} psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f /sql/02_itag_model.sql diff --git a/build/itag-database/sql/01_itag_functions.sql b/build/itag-database/sql/01_itag_functions.sql index d30de8f..b1215a7 100644 --- a/build/itag-database/sql/01_itag_functions.sql +++ b/build/itag-database/sql/01_itag_functions.sql @@ -7,18 +7,18 @@ -- -- Create IMMUTABLE unaccent function -- -CREATE OR REPLACE FUNCTION public.f_unaccent(text) RETURNS text AS -$func$ -SELECT public.unaccent('public.unaccent', $1) -- schema-qualify function and dictionary -$func$ LANGUAGE sql IMMUTABLE; +CREATE OR REPLACE FUNCTION public.f_unaccent(text) +RETURNS TEXT AS $$ + SELECT public.unaccent('public.unaccent', $1) -- schema-qualify function and dictionary +$$ LANGUAGE sql IMMUTABLE; -- -- Return a transliterated version of input string in lowercase -- -CREATE OR REPLACE FUNCTION normalize(input TEXT, separator text DEFAULT '') -RETURNS TEXT AS $$ +CREATE OR REPLACE FUNCTION public.normalize(input text, separator text DEFAULT '') +RETURNS text AS $$ BEGIN - RETURN translate(lower(public.f_unaccent(input)), ' '',:-\`\´\‘\’_' , separator); + RETURN translate(lower(public.f_unaccent(input)), ' '',:-`´‘’_' , separator); END $$ LANGUAGE 'plpgsql' IMMUTABLE; @@ -26,7 +26,7 @@ $$ LANGUAGE 'plpgsql' IMMUTABLE; -- Return a transliterated version of input string which the first letter of each word -- is in uppercase and the remaining characters in lowercase -- -CREATE OR REPLACE FUNCTION normalize_initcap(input TEXT, separator text DEFAULT '') +CREATE OR REPLACE FUNCTION public.normalize_initcap(input TEXT, separator text DEFAULT '') RETURNS TEXT AS $$ BEGIN RETURN translate(initcap(public.f_unaccent(input)), ' '',:-\`\´\‘\’_' , separator); diff --git a/deploy b/deploy index 5ac8152..9819c22 100755 --- a/deploy +++ b/deploy @@ -176,8 +176,8 @@ do sleep 1; done -PHYSICAL_EXISTS=$(PGPASSWORD=${DATABASE_USER_PASSWORD} psql -XAt -d ${DATABASE_NAME} -U ${DATABASE_USER_NAME} -h ${DATABASE_HOST_SEEN_FROM_DOCKERHOST} -p ${DATABASE_EXPOSED_PORT} -c "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'datasources' AND table_name= 'physical')") -if [[ "${PHYSICAL_EXISTS}" == "0" ]]; then +PHYSICAL_EXISTS=$(PGPASSWORD=${ITAG_DATABASE_USER_PASSWORD} psql -XAt -d ${ITAG_DATABASE_NAME} -U ${ITAG_DATABASE_USER_NAME} -h ${DATABASE_HOST_SEEN_FROM_DOCKERHOST} -p ${ITAG_DATABASE_EXPOSED_PORT} -c "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'datasources' AND table_name= 'physical')") +if [[ "${PHYSICAL_EXISTS}" == "f" ]]; then echo -e "${YELLOW}[WARNING] iTag database is not installed - you should run the *populateDatabase* script${NC}" else echo -e "${GREEN}[INFO] iTag database is complete${NC}" @@ -185,14 +185,14 @@ fi GPW_COUNT=$(PGPASSWORD=${ITAG_DATABASE_USER_PASSWORD} psql -U ${ITAG_DATABASE_USER_NAME} -d ${ITAG_DATABASE_NAME} -h ${DATABASE_HOST_SEEN_FROM_DOCKERHOST} -p ${ITAG_DATABASE_EXPOSED_PORT} -c "SELECT COUNT(*) FROM gpw.glp15ag60 LIMIT 1;" | head -3 | tail -1 | awk '{print $1}') if [[ "${GPW_COUNT}" == "0" ]]; then - echo -e "${YELLOW}[WARNING] Population data is not installed${NC}" + echo -e "${YELLOW}[WARNING] Population data is not installed${NC} - please contact ${YELLOW}${CONTACT}${NC} if you need it" else echo -e "${GREEN}[INFO] Population data is installed${NC}" fi LANDCOVER_COUNT=$(PGPASSWORD=${ITAG_DATABASE_USER_PASSWORD} psql -U ${ITAG_DATABASE_USER_NAME} -d ${ITAG_DATABASE_NAME} -h ${DATABASE_HOST_SEEN_FROM_DOCKERHOST} -p ${ITAG_DATABASE_EXPOSED_PORT} -c "SELECT COUNT(*) FROM landcover.landcover LIMIT 1;" | head -3 | tail -1 | awk '{print $1}') if [[ "${LANDCOVER_COUNT}" == "0" ]]; then - echo -e "[WARNING] Landcover data is not installed${NC}" + echo -e "${YELLOW}[WARNING] Landcover data is not installed${NC} - please contact ${YELLOW}${CONTACT}${NC} if you need it" else echo -e "${GREEN}[INFO] Landcover data is installed${NC}" fi