From 745c0a8b0a37b008768de50401ee0c705f2067d2 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Tue, 3 Nov 2015 17:35:40 +0100 Subject: [PATCH] Move namedplaces to cbd_geocoder extension --- geocoder/extension/Makefile | 3 +- .../cdb_geocoder_namedplaces_test.out | 12 ---- .../sql/0.0.1/15_country_decoder_table.sql | 54 +++++++++++++++++ geocoder/extension/sql/0.0.1/20_admin1.sql | 58 ------------------ .../sql/0.0.1/40_namedplaces.sql} | 60 ------------------- .../sql/cdb_geocoder_namedplaces_test.sql | 15 ----- geocoder/namedplace/extension/.gitignore | 3 - geocoder/namedplace/extension/Makefile | 8 --- geocoder/namedplace/extension/README.md | 36 ----------- .../cdb_geocoder_namedplaces.control | 6 -- 10 files changed, 56 insertions(+), 199 deletions(-) rename geocoder/{namedplace => }/extension/expected/cdb_geocoder_namedplaces_test.out (88%) create mode 100644 geocoder/extension/sql/0.0.1/15_country_decoder_table.sql rename geocoder/{namedplace/extension/cdb_geocoder_namedplaces--0.0.1.sql => extension/sql/0.0.1/40_namedplaces.sql} (89%) rename geocoder/{namedplace => }/extension/sql/cdb_geocoder_namedplaces_test.sql (82%) delete mode 100644 geocoder/namedplace/extension/.gitignore delete mode 100644 geocoder/namedplace/extension/Makefile delete mode 100644 geocoder/namedplace/extension/README.md delete mode 100644 geocoder/namedplace/extension/cdb_geocoder_namedplaces.control diff --git a/geocoder/extension/Makefile b/geocoder/extension/Makefile index ac1778e..d390592 100644 --- a/geocoder/extension/Makefile +++ b/geocoder/extension/Makefile @@ -8,7 +8,8 @@ REGRESS = \ 00_install_test \ cdb_geocoder_admin0_test \ cdb_geocoder_admin1_test \ - cdb_geocoder_ipaddr_test + cdb_geocoder_ipaddr_test \ + cdb_geocoder_namedplaces_test # postgres build stuff PG_CONFIG = pg_config diff --git a/geocoder/namedplace/extension/expected/cdb_geocoder_namedplaces_test.out b/geocoder/extension/expected/cdb_geocoder_namedplaces_test.out similarity index 88% rename from geocoder/namedplace/extension/expected/cdb_geocoder_namedplaces_test.out rename to geocoder/extension/expected/cdb_geocoder_namedplaces_test.out index 53d0b30..1e654fe 100644 --- a/geocoder/namedplace/extension/expected/cdb_geocoder_namedplaces_test.out +++ b/geocoder/extension/expected/cdb_geocoder_namedplaces_test.out @@ -1,8 +1,3 @@ -CREATE EXTENSION postgis; -CREATE EXTENSION schema_triggers; -CREATE EXTENSION plpythonu; -CREATE EXTENSION cartodb; -CREATE EXTENSION cdb_geocoder_namedplaces; -- Check that the different geocoding functions are callable, should return success = false SELECT (geocode_namedplace(Array['Madrid', 'New York City', 'sunapee'])).*; q | geom | success @@ -51,13 +46,6 @@ SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array Portland | Maine | USA | | f (3 rows) --- Mock the varnish invalidation function -CREATE OR REPLACE FUNCTION public.cdb_invalidate_varnish(table_name text) RETURNS void AS $$ -BEGIN - RETURN; -END -$$ -LANGUAGE plpgsql; -- Add a named place source COPY global_cities_alternates_limited (geoname_id, name, the_geom, created_at, updated_at, the_geom_webmercator, preferred, lowername, cartodb_id, admin1_geonameid, iso2, admin1) FROM stdin; COPY global_cities_points_limited (geoname_id, name, asciiname, altnames, featclass, featcode, iso2, admin1, admin2, population, the_geom, created_at, updated_at, the_geom_webmercator, cartodb_id, lowername) FROM stdin; diff --git a/geocoder/extension/sql/0.0.1/15_country_decoder_table.sql b/geocoder/extension/sql/0.0.1/15_country_decoder_table.sql new file mode 100644 index 0000000..510fd3a --- /dev/null +++ b/geocoder/extension/sql/0.0.1/15_country_decoder_table.sql @@ -0,0 +1,54 @@ +CREATE TABLE country_decoder ( + name text, + nativename text, + tld text, + iso2 text, + ccn3 text, + iso3 text, + currency text, + callingcode text, + capital text, + altspellings text, + relevance text, + region text, + subregion text, + language text, + languagescodes text, + translations text, + population text, + latlng text, + demonym text, + borders text, + the_geom geometry(Geometry,4326), + cartodb_id integer NOT NULL, + created_at timestamp with time zone DEFAULT now() NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + the_geom_webmercator geometry(Geometry,3857), + synbu text[], + synonyms text[], + users double precision +); + + +CREATE SEQUENCE country_decoder_cartodb_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER SEQUENCE country_decoder_cartodb_id_seq OWNED BY country_decoder.cartodb_id; +ALTER TABLE ONLY country_decoder ALTER COLUMN cartodb_id SET DEFAULT nextval('country_decoder_cartodb_id_seq'::regclass); + +ALTER TABLE ONLY country_decoder + ADD CONSTRAINT country_decoder_cartodb_id_key UNIQUE (cartodb_id); +ALTER TABLE ONLY country_decoder + ADD CONSTRAINT country_decoder_pkey PRIMARY KEY (cartodb_id); +ALTER TABLE country_decoder CLUSTER ON country_decoder_pkey; + + +CREATE INDEX country_decoder_the_geom_idx ON country_decoder USING gist (the_geom); +CREATE INDEX country_decoder_the_geom_webmercator_idx ON country_decoder USING gist (the_geom_webmercator); + +CREATE TRIGGER track_updates AFTER INSERT OR DELETE OR UPDATE OR TRUNCATE ON country_decoder FOR EACH STATEMENT EXECUTE PROCEDURE cartodb.cdb_tablemetadata_trigger(); +CREATE TRIGGER update_the_geom_webmercator_trigger BEFORE INSERT OR UPDATE OF the_geom ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_the_geom_webmercator(); +CREATE TRIGGER update_updated_at_trigger BEFORE UPDATE ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_updated_at(); diff --git a/geocoder/extension/sql/0.0.1/20_admin1.sql b/geocoder/extension/sql/0.0.1/20_admin1.sql index f2a85f7..1d04c63 100644 --- a/geocoder/extension/sql/0.0.1/20_admin1.sql +++ b/geocoder/extension/sql/0.0.1/20_admin1.sql @@ -113,64 +113,6 @@ $$; -- Support tables -CREATE TABLE country_decoder ( - name text, - nativename text, - tld text, - iso2 text, - ccn3 text, - iso3 text, - currency text, - callingcode text, - capital text, - altspellings text, - relevance text, - region text, - subregion text, - language text, - languagescodes text, - translations text, - population text, - latlng text, - demonym text, - borders text, - the_geom geometry(Geometry,4326), - cartodb_id integer NOT NULL, - created_at timestamp with time zone DEFAULT now() NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - the_geom_webmercator geometry(Geometry,3857), - synbu text[], - synonyms text[], - users double precision -); - -CREATE SEQUENCE country_decoder_cartodb_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; -ALTER SEQUENCE country_decoder_cartodb_id_seq OWNED BY country_decoder.cartodb_id; -ALTER TABLE ONLY country_decoder ALTER COLUMN cartodb_id SET DEFAULT nextval('country_decoder_cartodb_id_seq'::regclass); - - -ALTER TABLE ONLY country_decoder - ADD CONSTRAINT country_decoder_cartodb_id_key UNIQUE (cartodb_id); -ALTER TABLE ONLY country_decoder - ADD CONSTRAINT country_decoder_pkey PRIMARY KEY (cartodb_id); - -ALTER TABLE country_decoder CLUSTER ON country_decoder_pkey; - - -CREATE INDEX country_decoder_the_geom_idx ON country_decoder USING gist (the_geom); -CREATE INDEX country_decoder_the_geom_webmercator_idx ON country_decoder USING gist (the_geom_webmercator); - - -CREATE TRIGGER track_updates AFTER INSERT OR DELETE OR UPDATE OR TRUNCATE ON country_decoder FOR EACH STATEMENT EXECUTE PROCEDURE cartodb.cdb_tablemetadata_trigger(); -CREATE TRIGGER update_the_geom_webmercator_trigger BEFORE INSERT OR UPDATE OF the_geom ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_the_geom_webmercator(); -CREATE TRIGGER update_updated_at_trigger BEFORE UPDATE ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_updated_at(); - - CREATE TABLE global_province_polygons ( the_geom geometry(Geometry,4326), adm1_code text, diff --git a/geocoder/namedplace/extension/cdb_geocoder_namedplaces--0.0.1.sql b/geocoder/extension/sql/0.0.1/40_namedplaces.sql similarity index 89% rename from geocoder/namedplace/extension/cdb_geocoder_namedplaces--0.0.1.sql rename to geocoder/extension/sql/0.0.1/40_namedplaces.sql index 6dc537e..26e0f64 100644 --- a/geocoder/namedplace/extension/cdb_geocoder_namedplaces--0.0.1.sql +++ b/geocoder/extension/sql/0.0.1/40_namedplaces.sql @@ -1,11 +1,7 @@ --- Complain if script is sourced in psql, rather than via CREATE EXTENSION -\echo Use "CREATE EXTENSION cdb_geocoder_namedplaces" to load this file. \quit - -- Response types for namedplaces geocoder CREATE TYPE geocode_namedplace_country_v1 AS (q text, c text, geom geometry, success boolean); CREATE TYPE geocode_namedplace_v1 AS (q text, geom geometry, success boolean); CREATE TYPE geocode_admin1_country_v1 AS (q text, a1 text, c text, geom geometry, success boolean); -CREATE TYPE geocode_admin_country_v1 AS (q text, c text, geom geometry, success boolean); -- Public API functions -- --- Geocoding function --- @@ -346,62 +342,6 @@ CREATE TRIGGER update_the_geom_webmercator_trigger BEFORE INSERT OR UPDATE OF th CREATE TRIGGER update_updated_at_trigger BEFORE UPDATE ON admin1_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_updated_at(); -CREATE TABLE country_decoder ( - name text, - nativename text, - tld text, - iso2 text, - ccn3 text, - iso3 text, - currency text, - callingcode text, - capital text, - altspellings text, - relevance text, - region text, - subregion text, - language text, - languagescodes text, - translations text, - population text, - latlng text, - demonym text, - borders text, - the_geom geometry(Geometry,4326), - cartodb_id integer NOT NULL, - created_at timestamp with time zone DEFAULT now() NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - the_geom_webmercator geometry(Geometry,3857), - synbu text[], - synonyms text[], - users double precision -); - - -CREATE SEQUENCE country_decoder_cartodb_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; -ALTER SEQUENCE country_decoder_cartodb_id_seq OWNED BY country_decoder.cartodb_id; -ALTER TABLE ONLY country_decoder ALTER COLUMN cartodb_id SET DEFAULT nextval('country_decoder_cartodb_id_seq'::regclass); - -ALTER TABLE ONLY country_decoder - ADD CONSTRAINT country_decoder_cartodb_id_key UNIQUE (cartodb_id); -ALTER TABLE ONLY country_decoder - ADD CONSTRAINT country_decoder_pkey PRIMARY KEY (cartodb_id); -ALTER TABLE country_decoder CLUSTER ON country_decoder_pkey; - - -CREATE INDEX country_decoder_the_geom_idx ON country_decoder USING gist (the_geom); -CREATE INDEX country_decoder_the_geom_webmercator_idx ON country_decoder USING gist (the_geom_webmercator); - -CREATE TRIGGER track_updates AFTER INSERT OR DELETE OR UPDATE OR TRUNCATE ON country_decoder FOR EACH STATEMENT EXECUTE PROCEDURE cartodb.cdb_tablemetadata_trigger(); -CREATE TRIGGER update_the_geom_webmercator_trigger BEFORE INSERT OR UPDATE OF the_geom ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_the_geom_webmercator(); -CREATE TRIGGER update_updated_at_trigger BEFORE UPDATE ON country_decoder FOR EACH ROW EXECUTE PROCEDURE cartodb._cdb_update_updated_at(); - - CREATE TABLE global_cities_points_limited ( geoname_id integer, name text, diff --git a/geocoder/namedplace/extension/sql/cdb_geocoder_namedplaces_test.sql b/geocoder/extension/sql/cdb_geocoder_namedplaces_test.sql similarity index 82% rename from geocoder/namedplace/extension/sql/cdb_geocoder_namedplaces_test.sql rename to geocoder/extension/sql/cdb_geocoder_namedplaces_test.sql index cbc2c91..91f06e2 100644 --- a/geocoder/namedplace/extension/sql/cdb_geocoder_namedplaces_test.sql +++ b/geocoder/extension/sql/cdb_geocoder_namedplaces_test.sql @@ -1,9 +1,3 @@ -CREATE EXTENSION postgis; -CREATE EXTENSION schema_triggers; -CREATE EXTENSION plpythonu; -CREATE EXTENSION cartodb; -CREATE EXTENSION cdb_geocoder_namedplaces; - -- Check that the different geocoding functions are callable, should return success = false SELECT (geocode_namedplace(Array['Madrid', 'New York City', 'sunapee'])).*; SELECT (geocode_namedplace(Array['Elche', 'Granada', 'Madrid'], 'Spain')).*; @@ -12,15 +6,6 @@ SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array SELECT (geocode_namedplace(Array['Portland'], 'Oregon', 'USA')).*; SELECT (geocode_namedplace(Array['Portland', 'Portland', 'New York City'], Array['Maine', 'Oregon', NULL], Array['USA'])).*; - --- Mock the varnish invalidation function -CREATE OR REPLACE FUNCTION public.cdb_invalidate_varnish(table_name text) RETURNS void AS $$ -BEGIN - RETURN; -END -$$ -LANGUAGE plpgsql; - -- Add a named place source COPY global_cities_alternates_limited (geoname_id, name, the_geom, created_at, updated_at, the_geom_webmercator, preferred, lowername, cartodb_id, admin1_geonameid, iso2, admin1) FROM stdin; 3128760 barcelona \N 2014-02-11 18:23:18.115612+00 2014-02-25 16:41:15.278786+00 \N t barcelona 7530944 409419 \N 56 diff --git a/geocoder/namedplace/extension/.gitignore b/geocoder/namedplace/extension/.gitignore deleted file mode 100644 index e710f0e..0000000 --- a/geocoder/namedplace/extension/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -results/ -regression.diffs -regression.out diff --git a/geocoder/namedplace/extension/Makefile b/geocoder/namedplace/extension/Makefile deleted file mode 100644 index ab1f0dc..0000000 --- a/geocoder/namedplace/extension/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -EXTENSION = cdb_geocoder_namedplaces -DATA = cdb_geocoder_namedplaces--0.0.1.sql -REGRESS = cdb_geocoder_namedplaces_test - -# postgres build stuff -PG_CONFIG = pg_config -PGXS := $(shell $(PG_CONFIG) --pgxs) -include $(PGXS) diff --git a/geocoder/namedplace/extension/README.md b/geocoder/namedplace/extension/README.md deleted file mode 100644 index 478c892..0000000 --- a/geocoder/namedplace/extension/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# CartoDB named places geocoder extension -Postgres extension for the CartoDB named places geocoder. It is meant to contain the functions and related objects needed to geocode by city names. It is not meant to contain the actual data used to geocode them. - -## Dependencies -This extension is thought to be used on top of CartoDB platform. Therefore a cartodb user is required to install the extension onto it. - -The following is a non-comprehensive list of dependencies: - -- Postgres 9.3+ -- Postgis extension -- Schema triggers extension -- CartoDB extension - -## Installation into the db cluster -This requires root privileges -``` -sudo make all install -``` - -## Execute tests -``` -PGUSER=postgres make installcheck -``` - -## Install onto a user's database -``` -psql -U cartodb_dev_user_367c0edc-b2ad-4bab-ad43-3d58a6179a93_db cartodb_dev_user_367c0edc-b2ad-4bab-ad43-3d58a6179a93_db -``` - -and then: - -```sql -CREATE EXTENSION cdb_geocoder_namedplaces; -``` - -The extension creation in the user's db does not require special privileges. It can be even created from the sql api. diff --git a/geocoder/namedplace/extension/cdb_geocoder_namedplaces.control b/geocoder/namedplace/extension/cdb_geocoder_namedplaces.control deleted file mode 100644 index 7da3164..0000000 --- a/geocoder/namedplace/extension/cdb_geocoder_namedplaces.control +++ /dev/null @@ -1,6 +0,0 @@ -# cdb geocoder namedplaces extension -comment = 'CartoDB named places internal geocoder' -default_version = '0.0.1' -relocatable = true -requires = cartodb -superuser = false