Merge pull request #9 from CartoDB/geocoder-api-client-extension
Geocoder api client extension
This commit is contained in:
commit
a707f0d294
1
client/.gitignore
vendored
1
client/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
results/
|
results/
|
||||||
regression.diffs
|
regression.diffs
|
||||||
regression.out
|
regression.out
|
||||||
|
cdb_geocoder_client--0.0.1.sql
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
# Makefile to generate the extension out of separate sql source files.
|
||||||
|
# Once a version is released, it is not meant to be changed. E.g: once version 0.0.1 is out, it SHALL NOT be changed.
|
||||||
|
EXTENSION = cdb_geocoder_client
|
||||||
|
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||||
|
|
||||||
|
DATA = $(EXTENSION)--$(EXTVERSION).sql
|
||||||
|
|
||||||
|
REGRESS = $(notdir $(basename $(wildcard sql/*test.sql)))
|
||||||
|
|
||||||
|
# postgres build stuff
|
||||||
|
PG_CONFIG = pg_config
|
||||||
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
|
include $(PGXS)
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES_DATA = $(wildcard sql/$(EXTVERSION)/*.sql)
|
||||||
|
|
||||||
|
$(DATA): $(SOURCES_DATA)
|
||||||
|
rm -f $@
|
||||||
|
cat $(SOURCES_DATA) >> $@
|
||||||
|
|
||||||
|
all: $(DATA)
|
||||||
|
|
||||||
|
# Only meant for development time, do not use once a version is released
|
||||||
|
devclean:
|
||||||
|
rm -f $(DATA)
|
@ -0,0 +1,6 @@
|
|||||||
|
# CartoDB geocoder client API extension
|
||||||
|
comment = 'CartoDB geocoder client API extension'
|
||||||
|
default_version = '0.0.1'
|
||||||
|
requires = 'plproxy'
|
||||||
|
superuser = true
|
||||||
|
schema = cdb_geocoder_client
|
5
client/expected/00_installation_test.out
Normal file
5
client/expected/00_installation_test.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
-- Install dependencies
|
||||||
|
CREATE EXTENSION postgis;
|
||||||
|
CREATE EXTENSION plproxy;
|
||||||
|
-- Install the extension
|
||||||
|
CREATE EXTENSION cdb_geocoder_client;
|
2
client/sql/0.0.1/00_header.sql
Normal file
2
client/sql/0.0.1/00_header.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "CREATE EXTENSION cdb_geocoder_client" to load this file. \quit
|
38
client/sql/0.0.1/05_geocoder_server_conf.sql
Normal file
38
client/sql/0.0.1/05_geocoder_server_conf.sql
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
--
|
||||||
|
-- This extension has its own table for configurations.
|
||||||
|
--
|
||||||
|
-- The table and the function are considered to be private and therefore
|
||||||
|
-- no permissions are granted for any other user but the creator.
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS _config ( KEY TEXT PRIMARY KEY, VALUE JSON NOT NULL );
|
||||||
|
|
||||||
|
-- Needed to dump config in backups
|
||||||
|
-- This can only be called from an SQL script executed by CREATE EXTENSION
|
||||||
|
SELECT pg_catalog.pg_extension_config_dump('_config', '');
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION _config_set(key text, value JSON)
|
||||||
|
RETURNS VOID AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM _config_remove(key);
|
||||||
|
EXECUTE 'INSERT INTO _config (KEY, VALUE) VALUES ($1, $2);' USING key, value;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE PLPGSQL VOLATILE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION _config_remove(key text)
|
||||||
|
RETURNS VOID AS $$
|
||||||
|
BEGIN
|
||||||
|
EXECUTE 'DELETE FROM _config WHERE KEY = $1;' USING key;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE PLPGSQL VOLATILE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION _config_get(key text)
|
||||||
|
RETURNS JSON AS $$
|
||||||
|
DECLARE
|
||||||
|
value JSON;
|
||||||
|
BEGIN
|
||||||
|
EXECUTE 'SELECT VALUE FROM _config WHERE KEY = $1;' INTO value USING key;
|
||||||
|
RETURN value;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE PLPGSQL STABLE;
|
29
client/sql/0.0.1/10_admin0.sql
Normal file
29
client/sql/0.0.1/10_admin0.sql
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
--
|
||||||
|
-- Public geocoder API function
|
||||||
|
--
|
||||||
|
-- These are the only ones with permissions to publicuser role
|
||||||
|
-- and should also be the only ones with SECURITY DEFINER
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION geocode_admin0_polygons(country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
db_connection_str text;
|
||||||
|
ret Geometry;
|
||||||
|
BEGIN
|
||||||
|
SELECT _config_get('db_connection_str') INTO db_connection_str;
|
||||||
|
SELECT _geocode_admin0_polygons(session_user, txid_current(), db_connection_str, country_name) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO: review all permissions stuff [I'd explicitly grant permissions to the public functions]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION _geocode_admin0_polygons(user_id name, tx_id bigint, db_connection_str text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
-- TODO check if we can move the config to its own function
|
||||||
|
CONNECT db_connection_str;
|
||||||
|
SELECT geocode_admin0(user_id, tx_id, country_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
6
client/sql/00_installation_test.sql
Normal file
6
client/sql/00_installation_test.sql
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
-- Install dependencies
|
||||||
|
CREATE EXTENSION postgis;
|
||||||
|
CREATE EXTENSION plproxy;
|
||||||
|
|
||||||
|
-- Install the extension
|
||||||
|
CREATE EXTENSION cdb_geocoder_client;
|
0
client/sql/10_admin0_test.sql
Normal file
0
client/sql/10_admin0_test.sql
Normal file
@ -1,6 +1,6 @@
|
|||||||
# cdb geocoder server extension
|
# cdb geocoder server extension
|
||||||
comment = 'CartoDB server geocoder extension'
|
comment = 'CartoDB server geocoder extension'
|
||||||
default_version = '0.0.1'
|
default_version = '0.0.1'
|
||||||
requires = 'plpythonu, schema_triggers, postgis, cdb_geocoder'
|
requires = 'plpythonu, postgis, cdb_geocoder'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_geocoder_server
|
schema = cdb_geocoder_server
|
||||||
|
Loading…
Reference in New Issue
Block a user