Initial cdb_geocoder_server commit
This commit is contained in:
@@ -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_server
|
||||
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)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
# Geocoder API Server
|
||||
The CartoDB Geocoder SQL API server
|
||||
|
||||
21
server/cdb_geocoder_server--0.0.1.sql
Normal file
21
server/cdb_geocoder_server--0.0.1.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
-- 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)
|
||||
RETURNS BOOLEAN
|
||||
AS $$
|
||||
import os
|
||||
|
||||
response = os.system("ping -c 1 " + hostname)
|
||||
|
||||
return False if response else True
|
||||
$$ LANGUAGE plpythonu VOLATILE;
|
||||
|
||||
-- Returns current pwd
|
||||
CREATE OR REPLACE FUNCTION pwd()
|
||||
RETURNS TEXT
|
||||
AS $$
|
||||
import os
|
||||
|
||||
return os.getcwd()
|
||||
$$ LANGUAGE plpythonu VOLATILE;
|
||||
@@ -0,0 +1,6 @@
|
||||
# cdb geocoder server extension
|
||||
comment = 'CartoDB server geocoder extension'
|
||||
default_version = '0.0.1'
|
||||
relocatable = true
|
||||
requires = cartodb
|
||||
superuser = true
|
||||
|
||||
14
server/expected/00_install_test.out
Normal file
14
server/expected/00_install_test.out
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Install dependencies
|
||||
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;
|
||||
14
server/expected/10_helper_test.out
Normal file
14
server/expected/10_helper_test.out
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Check that check_host is working
|
||||
select check_host('cartodb.com');
|
||||
check_host
|
||||
------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- Check that check_pwd is working
|
||||
select pwd();
|
||||
pwd
|
||||
------------------------------
|
||||
/var/lib/postgresql/9.3/main
|
||||
(1 row)
|
||||
|
||||
2
server/sql/0.0.1/00_header.sql
Normal file
2
server/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_server" to load this file. \quit
|
||||
19
server/sql/0.0.1/10_helper.sql
Normal file
19
server/sql/0.0.1/10_helper.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Check if a given host is up by performing a ping -c 1 call.
|
||||
CREATE OR REPLACE FUNCTION check_host(hostname TEXT)
|
||||
RETURNS BOOLEAN
|
||||
AS $$
|
||||
import os
|
||||
|
||||
response = os.system("ping -c 1 " + hostname)
|
||||
|
||||
return False if response else True
|
||||
$$ LANGUAGE plpythonu VOLATILE;
|
||||
|
||||
-- Returns current pwd
|
||||
CREATE OR REPLACE FUNCTION pwd()
|
||||
RETURNS TEXT
|
||||
AS $$
|
||||
import os
|
||||
|
||||
return os.getcwd()
|
||||
$$ LANGUAGE plpythonu VOLATILE;
|
||||
16
server/sql/00_install_test.sql
Normal file
16
server/sql/00_install_test.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Install dependencies
|
||||
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;
|
||||
5
server/sql/10_helper_test.sql
Normal file
5
server/sql/10_helper_test.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Check that check_host is working
|
||||
select check_host('cartodb.com');
|
||||
|
||||
-- Check that check_pwd is working
|
||||
select pwd();
|
||||
Reference in New Issue
Block a user