From d772033b45ee264bba856d49099fe6f77135922d Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Fri, 6 Nov 2015 18:13:57 +0100 Subject: [PATCH] Adds cdb_cartodb_server schema --- server/cdb_geocoder_server--0.0.1.sql | 20 ++++++++++++++++++-- server/cdb_geocoder_server.control | 4 ++-- server/expected/00_install_test.out | 8 -------- server/expected/10_helper_test.out | 10 +++++----- server/sql/0.0.1/10_helper.sql | 4 ++-- server/sql/00_install_test.sql | 8 -------- server/sql/10_helper_test.sql | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/server/cdb_geocoder_server--0.0.1.sql b/server/cdb_geocoder_server--0.0.1.sql index d3f297a..3b13869 100644 --- a/server/cdb_geocoder_server--0.0.1.sql +++ b/server/cdb_geocoder_server--0.0.1.sql @@ -1,7 +1,7 @@ -- Complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION cdb_geocoder_server" to load this file. \quit -- Check if a given host is up by performing a ping -c 1 call. -CREATE OR REPLACE FUNCTION check_host(hostname TEXT) +CREATE OR REPLACE FUNCTION cdb_geocoder_server._check_host(hostname TEXT) RETURNS BOOLEAN AS $$ import os @@ -12,10 +12,26 @@ AS $$ $$ LANGUAGE plpythonu VOLATILE; -- Returns current pwd -CREATE OR REPLACE FUNCTION pwd() +CREATE OR REPLACE FUNCTION cdb_geocoder_server._pwd() RETURNS TEXT AS $$ import os return os.getcwd() $$ LANGUAGE plpythonu VOLATILE; +-- Check if a given host is up by performing a ping -c 1 call. +CREATE OR REPLACE FUNCTION cdb_geocoder_server.geocode_street(searchtext TEXT, state TEXT DEFAULT NULL, country TEXT DEFAULT NULL) + RETURNS Geometry +AS $$ + from heremaps import heremapsgeocoder + + geocoder = heremapsgeocoder.Geocoder(app_id, app_code) + + results = geocoder.geocode_address(searchtext=searchtext, state=state, country=country) + coordinates = geocoder.extract_lng_lat_from_result(results[0]) + + plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"]) + point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0] + + return point['st_setsrid'] +$$ LANGUAGE plpythonu VOLATILE; diff --git a/server/cdb_geocoder_server.control b/server/cdb_geocoder_server.control index b5fee44..0bb778f 100644 --- a/server/cdb_geocoder_server.control +++ b/server/cdb_geocoder_server.control @@ -1,6 +1,6 @@ # cdb geocoder server extension comment = 'CartoDB server geocoder extension' default_version = '0.0.1' -relocatable = true -requires = cartodb +requires = 'plpythonu, schema_triggers, postgis' superuser = true +schema = cdb_geocoder_server diff --git a/server/expected/00_install_test.out b/server/expected/00_install_test.out index 17fb473..87cd9ce 100644 --- a/server/expected/00_install_test.out +++ b/server/expected/00_install_test.out @@ -2,13 +2,5 @@ CREATE EXTENSION postgis; CREATE EXTENSION schema_triggers; CREATE EXTENSION plpythonu; -CREATE EXTENSION cartodb; -- Install the extension CREATE EXTENSION cdb_geocoder_server; --- Mock the varnish invalidation function -CREATE OR REPLACE FUNCTION public.cdb_invalidate_varnish(table_name text) RETURNS void AS $$ -BEGIN - RETURN; -END -$$ -LANGUAGE plpgsql; diff --git a/server/expected/10_helper_test.out b/server/expected/10_helper_test.out index 5af9f10..4e9a2f5 100644 --- a/server/expected/10_helper_test.out +++ b/server/expected/10_helper_test.out @@ -1,13 +1,13 @@ -- Check that check_host is working -select check_host('cartodb.com'); - check_host ------------- +select cdb_geocoder_server._check_host('cartodb.com'); + _check_host +------------- t (1 row) -- Check that check_pwd is working -select pwd(); - pwd +select cdb_geocoder_server._pwd(); + _pwd ------------------------------ /var/lib/postgresql/9.3/main (1 row) diff --git a/server/sql/0.0.1/10_helper.sql b/server/sql/0.0.1/10_helper.sql index 86d9b79..59f5e02 100644 --- a/server/sql/0.0.1/10_helper.sql +++ b/server/sql/0.0.1/10_helper.sql @@ -1,5 +1,5 @@ -- Check if a given host is up by performing a ping -c 1 call. -CREATE OR REPLACE FUNCTION check_host(hostname TEXT) +CREATE OR REPLACE FUNCTION cdb_geocoder_server._check_host(hostname TEXT) RETURNS BOOLEAN AS $$ import os @@ -10,7 +10,7 @@ AS $$ $$ LANGUAGE plpythonu VOLATILE; -- Returns current pwd -CREATE OR REPLACE FUNCTION pwd() +CREATE OR REPLACE FUNCTION cdb_geocoder_server._pwd() RETURNS TEXT AS $$ import os diff --git a/server/sql/00_install_test.sql b/server/sql/00_install_test.sql index 4a2e8b3..04ee816 100644 --- a/server/sql/00_install_test.sql +++ b/server/sql/00_install_test.sql @@ -2,15 +2,7 @@ CREATE EXTENSION postgis; CREATE EXTENSION schema_triggers; CREATE EXTENSION plpythonu; -CREATE EXTENSION cartodb; -- Install the extension CREATE EXTENSION cdb_geocoder_server; --- Mock the varnish invalidation function -CREATE OR REPLACE FUNCTION public.cdb_invalidate_varnish(table_name text) RETURNS void AS $$ -BEGIN - RETURN; -END -$$ -LANGUAGE plpgsql; diff --git a/server/sql/10_helper_test.sql b/server/sql/10_helper_test.sql index e9586c3..c05abbd 100644 --- a/server/sql/10_helper_test.sql +++ b/server/sql/10_helper_test.sql @@ -1,5 +1,5 @@ -- Check that check_host is working -select check_host('cartodb.com'); +select cdb_geocoder_server._check_host('cartodb.com'); -- Check that check_pwd is working -select pwd(); +select cdb_geocoder_server._pwd();