From 9dbe854df71b5d4cb1f3186c493b6ba30ea2dd32 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 11 Jun 2014 10:02:55 +0200 Subject: [PATCH 1/5] Do not force re-cartodbfication on CREATE FROM unpackaged --- Makefile | 4 +- NEWS | 7 ++++ util/create_from_unpackaged.sh | 73 +++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 4a81f31..4c9012d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cartodb/Makefile EXTENSION = cartodb -EXTVERSION = 0.2.0 +EXTVERSION = 0.2.1dev SED = sed @@ -17,7 +17,7 @@ UPGRADABLE = \ unpackaged \ 0.1.0 \ 0.1.1 \ - 0.2.0dev \ + 0.2.0 \ $(EXTVERSION)next \ $(END) diff --git a/NEWS b/NEWS index cab3f59..2b20877 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +0.2.1dev - 2014-MM-DD +------------------ + +Enhancements: + + - Do not force re-cartodbfication on CREATE FROM unpackaged + 0.2.0 - 2014-06-09 ------------------ diff --git a/util/create_from_unpackaged.sh b/util/create_from_unpackaged.sh index 7b3cf69..109c9ae 100755 --- a/util/create_from_unpackaged.sh +++ b/util/create_from_unpackaged.sh @@ -4,7 +4,22 @@ ver=$1 input=cartodb--${ver}.sql output=cartodb--unpackaged--${ver}.sql -cat ${input} | grep -v 'duplicated extension$' > ${output} +echo "-- Script generated by $0 on `date`" > ${output} + +# Migrate CDB functions from public schema to cartodb schema +cat ${input} | + grep '^ *CREATE OR REPLACE FUNCTION' | + grep -v ' cartodb\.' | # should only match DDL hooks + sed 's/).*$/)/' | + sed 's/DEFAULT [^ ,)]*//g' | + sed 's/CREATE OR REPLACE FUNCTION /ALTER FUNCTION public./' | + sed 's/$/ SET SCHEMA cartodb;/' | + sed 's/^/DO LANGUAGE plpgsql \$\$ BEGIN /' | + sed "s/$/ EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'Got % (%)', SQLERRM, SQLSTATE; END; \$\$;/" | + cat >> ${output} + +# Upgrade all functions +cat ${input} | grep -v 'duplicated extension$' >> ${output} # Migrate CDB_TableMetadata cat >> ${output} <<'EOF' @@ -29,32 +44,34 @@ BEGIN DROP FUNCTION public._CDB_UserQuotaInBytes(); END; $$ LANGUAGE 'plpgsql'; - --- Cartodbfy tables with a trigger using 'CDB_CheckQuota' or --- 'CDB_TableMetadata_Trigger' from the 'public' schema -select cartodb.CDB_CartodbfyTable(relname::regclass) from ( - -- names of tables using public.CDB_CheckQuota or - -- public.CDB_TableMetadata_Trigger in their triggers - SELECT distinct c.relname - FROM - pg_trigger t, - pg_class c, - pg_proc p, - pg_namespace n - WHERE - n.nspname = 'public' AND - p.pronamespace = n.oid AND - p.proname IN ( 'cdb_checkquota', 'cdb_tablemetadata_trigger' ) AND - t.tgrelid = c.oid AND - p.oid = t.tgfoid -) as foo; EOF -# Drop functions from public schema -cat ${input} | - grep '^ *CREATE OR REPLACE FUNCTION' | - grep -v ' cartodb\.' | # should only match DDL hooks - sed 's/).*$/);/' | - sed 's/DEFAULT [^ ,)]*//g' | - sed 's/CREATE OR REPLACE FUNCTION /DROP FUNCTION public./' | - cat >> ${output} +## Cartodbfy tables with a trigger using 'CDB_CheckQuota' or +## 'CDB_TableMetadata_Trigger' from the 'public' schema +#cat >> ${output} <<'EOF' +#select cartodb.CDB_CartodbfyTable(relname::regclass) from ( +# -- names of tables using public.CDB_CheckQuota or +# -- public.CDB_TableMetadata_Trigger in their triggers +# SELECT distinct c.relname +# FROM +# pg_trigger t, +# pg_class c, +# pg_proc p, +# pg_namespace n +# WHERE +# n.nspname = 'public' AND +# p.pronamespace = n.oid AND +# p.proname IN ( 'cdb_checkquota', 'cdb_tablemetadata_trigger' ) AND +# t.tgrelid = c.oid AND +# p.oid = t.tgfoid +#) as foo; +#EOF + +## Drop any leftover function from public schema (there should be none) +#cat ${input} | +# grep '^ *CREATE OR REPLACE FUNCTION' | +# grep -v ' cartodb\.' | # should only match DDL hooks +# sed 's/).*$/);/' | +# sed 's/DEFAULT [^ ,)]*//g' | +# sed 's/CREATE OR REPLACE FUNCTION /DROP FUNCTION IF EXISTS public./' | +# cat >> ${output} From 81bbfcbda8b33c068c8b662afc7c8fd413546b3b Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 11 Jun 2014 11:25:25 +0200 Subject: [PATCH 2/5] Drop useless DEFAULT specification in plpgsql variable declarations --- NEWS | 1 + scripts-available/CDB_DateToNumber.sql | 2 +- scripts-available/CDB_StringToDate.sql | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 2b20877..caca6d7 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Enhancements: - Do not force re-cartodbfication on CREATE FROM unpackaged + - Drop useless DEFAULT specification in plpgsql variable declarations 0.2.0 - 2014-06-09 ------------------ diff --git a/scripts-available/CDB_DateToNumber.sql b/scripts-available/CDB_DateToNumber.sql index c879112..1b9a449 100644 --- a/scripts-available/CDB_DateToNumber.sql +++ b/scripts-available/CDB_DateToNumber.sql @@ -2,7 +2,7 @@ -- CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp) RETURNS double precision AS $$ -DECLARE output double precision DEFAULT NULL; +DECLARE output double precision; BEGIN BEGIN SELECT extract (EPOCH FROM input) INTO output; diff --git a/scripts-available/CDB_StringToDate.sql b/scripts-available/CDB_StringToDate.sql index cbdf4ec..fa2db05 100644 --- a/scripts-available/CDB_StringToDate.sql +++ b/scripts-available/CDB_StringToDate.sql @@ -2,7 +2,7 @@ -- CREATE OR REPLACE FUNCTION CDB_StringToDate(input character varying) RETURNS date AS $$ -DECLARE output DATE DEFAULT NULL; +DECLARE output DATE; BEGIN BEGIN output := input::date; From afcc2498c822166ddd83d49290d7073cd198a390 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 11 Jun 2014 16:27:11 +0200 Subject: [PATCH 3/5] List plpythonu requirement first, so get pg_catalog scanned before public Since "plpythonu" is installed in "pg_catalog" schema, requiring it from cartodb.control adds the "pg_catalog" to the search_path. Schemas are added to search_path in order of appearence in the "requires" directive of the cartodb.contorl, right after the name of schema written in the "schema" directive. So this commit changes the resulting search_path from: cartodb,schema_triggers,public,pg_catalog To: cartodb,pg_catalog,schema_triggers,public Preventing presence of objects in the "public" schema from changing interpretation of function signatures and body from this extension. Spotted in the real world in presence of a "date" table changing intepretation of CDB_StringToDate function. --- NEWS | 1 + cartodb.control.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index caca6d7..497d9b1 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Enhancements: - Do not force re-cartodbfication on CREATE FROM unpackaged - Drop useless DEFAULT specification in plpgsql variable declarations + - List plpythonu requirement first, so get pg_catalog scanned before public 0.2.0 - 2014-06-09 ------------------ diff --git a/cartodb.control.in b/cartodb.control.in index 3d783c7..c331343 100644 --- a/cartodb.control.in +++ b/cartodb.control.in @@ -3,4 +3,4 @@ comment = 'Turn a database into a cartodb user database.' superuser = true relocatable = false schema = cartodb -requires = 'schema_triggers, postgis, plpythonu' +requires = 'plpythonu, schema_triggers, postgis' From bc0966c46e813931cae243fefe1b3ff662ef6d94 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 11 Jun 2014 19:21:19 +0200 Subject: [PATCH 4/5] Do not add unique index on cartodb_id if already a primary key Closes #38 --- NEWS | 4 ++++ scripts-available/CDB_CartodbfyTable.sql | 2 +- test/CDB_CartodbfyTableTest.sql | 8 ++++++++ test/CDB_CartodbfyTableTest_expect | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 497d9b1..960e027 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ Enhancements: - Drop useless DEFAULT specification in plpgsql variable declarations - List plpythonu requirement first, so get pg_catalog scanned before public +Bug fixes: + + - Do not add unique index on cartodb_id if already a primary key (#38) + 0.2.0 - 2014-06-09 ------------------ diff --git a/scripts-available/CDB_CartodbfyTable.sql b/scripts-available/CDB_CartodbfyTable.sql index e69f187..ad56404 100644 --- a/scripts-available/CDB_CartodbfyTable.sql +++ b/scripts-available/CDB_CartodbfyTable.sql @@ -111,7 +111,7 @@ BEGIN AND a.attrelid = reloid AND NOT a.attisdropped AND a.attname = 'cartodb_id' - AND c.contype = 'u' ) -- unique + AND c.contype IN ( 'u', 'p' ) ) -- unique or pkey THEN sql := sql || ', ADD unique(cartodb_id)'; END IF; diff --git a/test/CDB_CartodbfyTableTest.sql b/test/CDB_CartodbfyTableTest.sql index e68cb8b..74ece18 100644 --- a/test/CDB_CartodbfyTableTest.sql +++ b/test/CDB_CartodbfyTableTest.sql @@ -200,6 +200,14 @@ SELECT CDB_CartodbfyTableCheck('t', 'unsequenced cartodb_id'); select cartodb_id FROM t; DROP TABLE t; +-- table with existing cartodb_id serial primary key +CREATE TABLE t ( cartodb_id serial primary key ); +SELECT CDB_CartodbfyTableCheck('t', 'cartodb_id serial primary key'); +SELECT c.conname, a.attname FROM pg_constraint c, pg_attribute a +WHERE c.conrelid = 't'::regclass and a.attrelid = c.conrelid +AND c.conkey[1] = a.attnum AND NOT a.attisdropped; +DROP TABLE t; + -- table with existing the_geom and created_at and containing null values -- Really, a test for surviving an longstanding PostgreSQL bug: -- http://www.postgresql.org/message-id/20140530143150.GA11051@localhost diff --git a/test/CDB_CartodbfyTableTest_expect b/test/CDB_CartodbfyTableTest_expect index c3dd05c..c5e79e6 100644 --- a/test/CDB_CartodbfyTableTest_expect +++ b/test/CDB_CartodbfyTableTest_expect @@ -45,6 +45,10 @@ unsequenced cartodb_id cartodbfied fine 1 DROP TABLE CREATE TABLE +cartodb_id serial primary key cartodbfied fine +t_pkey|cartodb_id +DROP TABLE +CREATE TABLE null geom and timestamp values cartodbfied fine DROP TABLE DROP FUNCTION From 9afc59da5e1dc781f041ead3e43da7f3d36b0138 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 11 Jun 2014 16:34:06 +0200 Subject: [PATCH 5/5] Set release date for 0.2.1 --- Makefile | 2 +- NEWS | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4c9012d..b734209 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cartodb/Makefile EXTENSION = cartodb -EXTVERSION = 0.2.1dev +EXTVERSION = 0.2.1 SED = sed diff --git a/NEWS b/NEWS index 960e027..5549f69 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,11 @@ -0.2.1dev - 2014-MM-DD +0.2.1 - 2014-06-11 ------------------ Enhancements: - Do not force re-cartodbfication on CREATE FROM unpackaged - Drop useless DEFAULT specification in plpgsql variable declarations - - List plpythonu requirement first, so get pg_catalog scanned before public + - List plpythonu requirement first, to get pg_catalog scanned before public Bug fixes: