Skip to content

Commit

Permalink
Correct itag function
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrom committed Aug 26, 2021
1 parent 96ab931 commit 844c139
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions build/itag-database/installDB.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

16 changes: 8 additions & 8 deletions build/itag-database/sql/01_itag_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
--
-- 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;

--
-- 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);
Expand Down
8 changes: 4 additions & 4 deletions deploy
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ 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}"
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
Expand Down

0 comments on commit 844c139

Please sign in to comment.