Merge branch 'b0.2'

Conflicts:
	Makefile
	NEWS
This commit is contained in:
Sandro Santilli 2014-06-11 19:30:32 +02:00
commit 1bb8b85503
9 changed files with 75 additions and 33 deletions

View File

@ -18,7 +18,7 @@ UPGRADABLE = \
0.1.0 \
0.1.1 \
0.2.0 \
0.2.0dev \
0.2.1 \
$(EXTVERSION)next \
$(END)

13
NEWS
View File

@ -1,6 +1,19 @@
0.3.0dev - 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, to 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
------------------

View File

@ -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'

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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}