Compare commits

...

15 Commits

Author SHA1 Message Date
Luis Bosque
cf2587ca54 New version 0.11.2 2015-10-19 14:35:10 +02:00
Luis Bosque
d1d5ed6df3 Optimize invalidation time logging 2015-10-19 14:09:52 +02:00
Luis Bosque
37160c7b35 Write invalidation duration in postgresql log 2015-10-16 18:23:18 +02:00
Alejandro Martínez
811c7474de Merge pull request #170 from CartoDB/fix-schema-group-sequence
Fix schema not being specified on pg_get_serial_sequence
2015-10-15 17:39:46 +02:00
Alejandro Martínez
1f63811383 Fix schema not being specified on pg_get_serial_sequence 2015-10-06 18:09:37 +02:00
Rafa de la Torre
913bfd72f8 New version 0.11.1
- Added CDB_DateToNumber(timestamp with time zone) [#169](https://github.com/CartoDB/cartodb-postgresql/pull/169)
- cartodbfy now discards cartodb_id candidates that contain nulls [#148](https://github.com/CartoDB/cartodb-postgresql/issues/148)
2015-10-06 14:45:35 +02:00
Rafa de la Torre
15dd4935d6 Merge pull request #168 from CartoDB/148-cartodbfy-checks-for-null-cartodb-id
148 cartodbfy checks for null cartodb id
2015-10-06 14:39:00 +02:00
Rafa de la Torre
39e558f494 Merge pull request #169 from CartoDB/2202-DateToNumber-with-time-zones
Changes CDB_DateToNumber() to accept timestamps with time zones 2202
2015-10-06 12:52:52 +02:00
Guido Fioravantti
03636fafc4 Update CONTRIBUTING.md 2015-10-06 11:33:56 +02:00
Guido Fioravantti
6b3b28f01f Makes CDB_DateToNumber() tests more intuitive 2202 2015-10-05 14:56:45 +02:00
Guido Fioravantti
186ed34ee5 Overloads CDB_DateToNumber() and adds test 2015-10-05 13:32:03 +02:00
Guido Fioravantti
e4ce12d1a3 Changes CDB_DateToNumber() to accept timestamps with time zones 2202 2015-10-05 11:51:13 +02:00
Guido Fioravantti
5de395a4a8 Uses CDB_CartodbfyTableCheck() 148 2015-09-29 19:01:30 +02:00
Guido Fioravantti
3429e93979 Makes cartodbfy check for null cartodb_id 2015-09-29 18:04:00 +02:00
Guido Fioravantti
777e8c6e4c Adds test to check cartodbfy works with null cartodb_id 2015-09-29 18:03:20 +02:00
11 changed files with 120 additions and 10 deletions

View File

@@ -44,7 +44,7 @@ the extension into your test database.
During development the cartodb extension version doesn't change with
every commit, so testing latest change requires cheating with PostgreSQL
so to enforce re-load of the scripts. To help with cheating, "make install"
as to enforce the scripts to reload. To help with cheating, "make install"
also installs migration scripts to go from "V" to "V"next and from "V"next
to "V". Example to upgrade a 0.2.0dev version:

View File

@@ -1,7 +1,7 @@
# cartodb/Makefile
EXTENSION = cartodb
EXTVERSION = 0.11.0
EXTVERSION = 0.11.2
SED = sed
@@ -51,6 +51,8 @@ UPGRADABLE = \
0.10.1 \
0.10.2 \
0.11.0 \
0.11.1 \
0.11.2 \
$(EXTVERSION)dev \
$(EXTVERSION)next \
$(END)

10
NEWS.md
View File

@@ -1,6 +1,16 @@
next (2015-mm-dd)
-----------------
0.11.2 (2015-10-19)
-------------------
* Fix schema not being specified on pg_get_serial_sequence [#170](https://github.com/CartoDB/cartodb-postgresql/pull/170)
* Log invalidation function call duration in seconds [#163](https://github.com/CartoDB/cartodb-postgresql/pull/163)
0.11.1 (2015-10-06)
-------------------
* Added CDB_DateToNumber(timestamp with time zone) [#169](https://github.com/CartoDB/cartodb-postgresql/pull/169)
* cartodbfy now discards cartodb_id candidates that contain nulls [#148](https://github.com/CartoDB/cartodb-postgresql/issues/148)
0.11.0 (2015-09-dd)
-------------------
* Groups API

View File

@@ -362,7 +362,7 @@ $$ LANGUAGE PLPGSQL;
-- As before, this drops all the metadata and geom sync triggers
--
-- (2) _CDB_Has_Usable_Primary_ID()
-- Returns TRUE if it can find a unique integer primary key named
-- Returns TRUE if it can find a unique and not null integer primary key named
-- 'cartodb_id' or can rename an existing key.
-- Returns FALSE otherwise.
--
@@ -551,7 +551,7 @@ BEGIN
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('found good ''%s''', const.pkey);
RETURN true;
-- Check and see if the column values are unique,
-- Check and see if the column values are unique and not null,
-- if they are, we can use this column...
ELSE
@@ -559,13 +559,17 @@ BEGIN
useable_key := true;
BEGIN
sql := Format('ALTER TABLE %s ADD CONSTRAINT %s_unique UNIQUE (%s)', reloid::text, const.pkey, const.pkey);
sql := Format('ALTER TABLE %s ADD CONSTRAINT %s_pk PRIMARY KEY (%s)', reloid::text, const.pkey, const.pkey);
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', sql;
EXECUTE sql;
EXCEPTION
-- Failed unique check...
WHEN unique_violation THEN
RAISE NOTICE 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('column %s is not unique', const.pkey);
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('column %s is not unique', const.pkey);
useable_key := false;
-- Failed not null check...
WHEN not_null_violation THEN
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('column %s contains nulls', const.pkey);
useable_key := false;
-- Other fatal error
WHEN others THEN
@@ -574,7 +578,7 @@ BEGIN
-- Clean up test constraint
IF useable_key THEN
PERFORM _CDB_SQL(Format('ALTER TABLE %s DROP CONSTRAINT %s_unique', reloid::text, const.pkey));
PERFORM _CDB_SQL(Format('ALTER TABLE %s DROP CONSTRAINT %s_pk', reloid::text, const.pkey));
-- Move non-unique column out of the way
ELSE

View File

@@ -13,3 +13,19 @@ RETURN output;
END;
$$
LANGUAGE 'plpgsql' STABLE STRICT;
-- Convert timestamp with time zone to double precision
--
CREATE OR REPLACE FUNCTION CDB_DateToNumber(input timestamp with time zone)
RETURNS double precision AS $$
DECLARE output double precision;
BEGIN
BEGIN
SELECT extract (EPOCH FROM input) INTO output;
EXCEPTION WHEN OTHERS THEN
RETURN NULL;
END;
RETURN output;
END;
$$
LANGUAGE 'plpgsql' STABLE STRICT;

View File

@@ -163,7 +163,7 @@ BEGIN
group_role := cartodb._CDB_Group_GroupRole(group_name);
FOR column_name IN EXECUTE 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = current_database() AND TABLE_SCHEMA = $1 AND TABLE_NAME = $2 AND COLUMN_DEFAULT LIKE ''nextval%''' USING username, table_name
LOOP
EXECUTE 'SELECT PG_GET_SERIAL_SEQUENCE($1, $2)' USING table_name, column_name INTO sequence_name;
EXECUTE format('SELECT PG_GET_SERIAL_SEQUENCE(''%I.%I'', ''%I'')', username, table_name, column_name) INTO sequence_name;
IF sequence_name IS NOT NULL THEN
IF do_grant THEN
-- Here %s is needed since sequence_name has quotes

View File

@@ -64,6 +64,10 @@ DECLARE
tabname TEXT;
rec RECORD;
found BOOL;
function_start timestamptz;
function_end timestamptz;
function_duration float;
log_error_verbosity_value text;
BEGIN
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
@@ -72,6 +76,8 @@ BEGIN
tabname = OLD.tabname;
END IF;
function_start := clock_timestamp();
-- Notify table data update
-- This needs a little bit more of research regarding security issues
-- see https://github.com/CartoDB/cartodb/pull/241
@@ -105,7 +111,14 @@ BEGIN
EXIT;
END LOOP;
IF NOT found THEN RAISE WARNING 'Missing cdb_invalidate_varnish()'; END IF;
function_end := clock_timestamp();
SELECT extract(epoch from (function_end - function_start)) INTO function_duration;
SELECT setting INTO log_error_verbosity_value FROM pg_settings WHERE name='log_error_verbosity';
SET log_error_verbosity=TERSE;
RAISE LOG 'invalidation_duration: %', function_duration::text;
PERFORM 'SET log_error_verbosity= ' || log_error_verbosity_value;
RETURN NULL;
END;
$$

View File

@@ -250,7 +250,7 @@ INSERT INTO existing_cartodb_id (cartodb_id, description) VALUES
(20, 'b'),
(30, 'c');
SELECT CDB_CartodbfyTableCheck('existing_cartodb_id', 'Existing cartodb_id values are respected #138');
SELECT * from existing_cartodb_id;
SELECT cartodb_id,the_geom,the_geom_webmercator,description,name from existing_cartodb_id;
DROP TABLE existing_cartodb_id;
-- Table with both the_geom and wkb_geometry
@@ -281,6 +281,44 @@ INSERT INTO many_colliding_columns VALUES (
SELECT CDB_CartodbfyTableCheck('many_colliding_columns', 'Many colliding columns #141');
DROP TABLE many_colliding_columns;
-- Table with null cartodb_id
CREATE TABLE test (
cartodb_id integer
);
INSERT INTO test VALUES
(1),
(2),
(NULL),
(3);
SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148');
SELECT cartodb_id, cartodb_id_1 from test;
DROP TABLE test;
-- Table with non unique cartodb_id
CREATE TABLE test (
cartodb_id integer
);
INSERT INTO test VALUES
(1),
(2),
(2);
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148');
SELECT cartodb_id, cartodb_id_1 from test;
DROP TABLE test;
-- Table with non unique and null cartodb_id
CREATE TABLE test (
cartodb_id integer
);
INSERT INTO test VALUES
(1),
(2),
(NULL),
(2);
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148');
SELECT cartodb_id, cartodb_id_1 from test;
DROP TABLE test;
-- TODO: table with existing custom-triggered the_geom

View File

@@ -79,5 +79,28 @@ CREATE TABLE
INSERT 0 1
Many colliding columns #141 cartodbfied fine
DROP TABLE
CREATE TABLE
INSERT 0 4
Table with null cartodb_id #148 cartodbfied fine
1|1
2|2
3|
4|3
DROP TABLE
CREATE TABLE
INSERT 0 3
Table with non unique cartodb_id #148 cartodbfied fine
1|1
2|2
3|2
DROP TABLE
CREATE TABLE
INSERT 0 4
Table with non unique and null cartodb_id #148 cartodbfied fine
1|1
2|2
3|
4|2
DROP TABLE
DROP FUNCTION
DROP FUNCTION

View File

@@ -0,0 +1,2 @@
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00'::timestamp);
SELECT * FROM CDB_DateToNumber('1999-01-08 00:00:00+05'::timestamp with time zone);

View File

@@ -0,0 +1,2 @@
915753600
915735600