|
|
@ -34,20 +34,10 @@ BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
sql := 'INSERT INTO ' || tabname::text || '(the_geom) values ( CDB_LatLng(2,1) ) RETURNING cartodb_id';
|
|
|
|
sql := 'INSERT INTO ' || tabname::text || '(the_geom) values ( CDB_LatLng(2,1) ) RETURNING cartodb_id';
|
|
|
|
EXECUTE sql INTO STRICT id;
|
|
|
|
EXECUTE sql INTO STRICT id;
|
|
|
|
sql := 'SELECT created_at,updated_at,the_geom_webmercator FROM '
|
|
|
|
sql := 'SELECT the_geom_webmercator FROM '
|
|
|
|
|| tabname::text || ' WHERE cartodb_id = ' || id;
|
|
|
|
|| tabname::text || ' WHERE cartodb_id = ' || id;
|
|
|
|
EXECUTE sql INTO STRICT rec;
|
|
|
|
EXECUTE sql INTO STRICT rec;
|
|
|
|
|
|
|
|
|
|
|
|
-- Check created_at and updated_at at creation time
|
|
|
|
|
|
|
|
lag = rec.created_at - now();
|
|
|
|
|
|
|
|
IF lag > '1 second' THEN
|
|
|
|
|
|
|
|
RAISE EXCEPTION 'created_at not defaulting to now() after insert [ valued % ago ]', lag;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
lag = rec.updated_at - now();
|
|
|
|
|
|
|
|
IF lag > '1 second' THEN
|
|
|
|
|
|
|
|
RAISE EXCEPTION 'updated_at not defaulting to now() after insert [ valued % ago ]', lag;
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Check the_geom_webmercator trigger
|
|
|
|
-- Check the_geom_webmercator trigger
|
|
|
|
IF round(st_x(rec.the_geom_webmercator)) != 111319 THEN
|
|
|
|
IF round(st_x(rec.the_geom_webmercator)) != 111319 THEN
|
|
|
|
RAISE EXCEPTION 'the_geom_webmercator X is % (expecting 111319)', round(st_x(rec.the_geom_webmercator));
|
|
|
|
RAISE EXCEPTION 'the_geom_webmercator X is % (expecting 111319)', round(st_x(rec.the_geom_webmercator));
|
|
|
@ -112,15 +102,6 @@ BEGIN
|
|
|
|
RAISE EXCEPTION '% gist indices found on the_geom and the_geom_webmercator, expected 2', tmp;
|
|
|
|
RAISE EXCEPTION '% gist indices found on the_geom and the_geom_webmercator, expected 2', tmp;
|
|
|
|
END IF;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
|
|
-- Check null constraint on cartodb_id, created_at, updated_at
|
|
|
|
|
|
|
|
SELECT count(*) FROM pg_attribute a, pg_class c WHERE c.oid = tabname::oid
|
|
|
|
|
|
|
|
AND a.attrelid = c.oid AND NOT a.attisdropped AND a.attname in
|
|
|
|
|
|
|
|
( 'cartodb_id', 'created_at', 'updated_at' )
|
|
|
|
|
|
|
|
AND NOT a.attnotnull INTO strict tmp;
|
|
|
|
|
|
|
|
IF tmp > 0 THEN
|
|
|
|
|
|
|
|
RAISE EXCEPTION 'cartodb_id or created_at or updated_at are missing not-null constraint';
|
|
|
|
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Cleanup
|
|
|
|
-- Cleanup
|
|
|
|
sql := 'DELETE FROM ' || tabname::text || ' WHERE cartodb_id = ' || id;
|
|
|
|
sql := 'DELETE FROM ' || tabname::text || ' WHERE cartodb_id = ' || id;
|
|
|
|
EXECUTE sql;
|
|
|
|
EXECUTE sql;
|
|
|
@ -170,18 +151,6 @@ SELECT CDB_CartodbfyTableCheck('t', 'trigger-protected the_geom');
|
|
|
|
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM t;
|
|
|
|
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM t;
|
|
|
|
DROP TABLE t;
|
|
|
|
DROP TABLE t;
|
|
|
|
|
|
|
|
|
|
|
|
-- table with existing updated_at and created_at fields ot type text
|
|
|
|
|
|
|
|
CREATE TABLE t AS SELECT NOW()::text as created_at,
|
|
|
|
|
|
|
|
NOW()::text as updated_at,
|
|
|
|
|
|
|
|
NOW() as reftime;
|
|
|
|
|
|
|
|
SELECT CDB_CartodbfyTableCheck('t', 'text timestamps');
|
|
|
|
|
|
|
|
SELECT extract(secs from reftime-created_at),
|
|
|
|
|
|
|
|
extract(secs from reftime-updated_at) FROM t;
|
|
|
|
|
|
|
|
CREATE VIEW v AS SELECT * FROM t;
|
|
|
|
|
|
|
|
SELECT CDB_CartodbfyTableCheck('t', 'cartodbfied with view');
|
|
|
|
|
|
|
|
DROP VIEW v;
|
|
|
|
|
|
|
|
DROP TABLE t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- table with existing cartodb_id field of type text
|
|
|
|
-- table with existing cartodb_id field of type text
|
|
|
|
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
|
|
|
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
|
|
|
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
|
|
|
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
|
|
@ -208,22 +177,6 @@ WHERE c.conrelid = 't'::regclass and a.attrelid = c.conrelid
|
|
|
|
AND c.conkey[1] = a.attnum AND NOT a.attisdropped;
|
|
|
|
AND c.conkey[1] = a.attnum AND NOT a.attisdropped;
|
|
|
|
DROP TABLE t;
|
|
|
|
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
|
|
|
|
|
|
|
|
CREATE TABLE t (
|
|
|
|
|
|
|
|
the_geom geometry(Geometry,4326),
|
|
|
|
|
|
|
|
created_at timestamptz,
|
|
|
|
|
|
|
|
updated_at timestamptz
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
COPY t (the_geom, created_at, updated_at) FROM stdin;
|
|
|
|
|
|
|
|
0106000020E610000001000000010300000001000000050000009EB8244146435BC017B65E062AD343409EB8244146435BC0F51AF6E2708044400B99891683765AC0F51AF6E2708044400B99891683765AC017B65E062AD343409EB8244146435BC017B65E062AD34340 2012-06-06 21:59:08 2013-06-10 20:17:20
|
|
|
|
|
|
|
|
0106000020E61000000100000001030000000100000005000000DA7763431A1A5CC0FBCEE869313C3A40DA7763431A1A5CC09C1B8F55BC494440F9F4A9C7993356C09C1B8F55BC494440F9F4A9C7993356C0FBCEE869313C3A40DA7763431A1A5CC0FBCEE869313C3A40 2012-06-06 21:59:08 2013-06-10 20:17:20
|
|
|
|
|
|
|
|
\N \N \N
|
|
|
|
|
|
|
|
\.
|
|
|
|
|
|
|
|
SELECT CDB_CartodbfyTableCheck('t', 'null geom and timestamp values');
|
|
|
|
|
|
|
|
DROP TABLE t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TODO: table with existing custom-triggered the_geom
|
|
|
|
-- TODO: table with existing custom-triggered the_geom
|
|
|
|
|
|
|
|
|
|
|
|
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
|
|
|
|
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
|
|
|
|