Make cartodb_id inconsistencies fail and update tests

This commit is contained in:
Carla Iriberri
2016-03-08 11:58:30 +01:00
parent 73906b60da
commit f4b51807a1
3 changed files with 24 additions and 28 deletions
+3 -7
View File
@@ -527,7 +527,7 @@ BEGIN
useable_key := false; useable_key := false;
-- Other fatal error -- Other fatal error
WHEN others THEN WHEN others THEN
PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: %s', SQLERRM)); PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: not valid %s', SQLERRM));
END; END;
-- Clean up test constraint -- Clean up test constraint
@@ -538,13 +538,9 @@ BEGIN
ELSE ELSE
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %',
Format('found non-unique ''%s'', renaming it', const.pkey); Format('found non-unique ''%s''', const.pkey);
PERFORM _CDB_SQL( PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: non-unique %s', const.pkey));
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
reloid::text, rec.attname,
cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
'_CDB_Has_Usable_Primary_ID');
END IF; END IF;
+4 -4
View File
@@ -178,7 +178,7 @@ DROP TABLE t;
-- table with empty cartodb_id field of type text -- table with empty cartodb_id field of type text
CREATE TABLE t AS SELECT null::text as cartodb_id; CREATE TABLE t AS SELECT null::text as cartodb_id;
SELECT CDB_CartodbfyTableCheck('t', 'empty text cartodb_id'); SELECT CDB_CartodbfyTableCheck('t', 'empty text cartodb_id');
select cartodb_id,cartodb_id_0 FROM t; SELECT cartodb_id from t;
DROP TABLE t; DROP TABLE t;
-- table with existing cartodb_id field of type int4 not sequenced -- table with existing cartodb_id field of type int4 not sequenced
@@ -294,7 +294,7 @@ INSERT INTO test VALUES
(NULL), (NULL),
(3); (3);
SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148'); SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148');
SELECT cartodb_id, cartodb_id_0 from test; SELECT cartodb_id from test;
DROP TABLE test; DROP TABLE test;
-- Table with non unique cartodb_id -- Table with non unique cartodb_id
@@ -306,7 +306,7 @@ INSERT INTO test VALUES
(2), (2),
(2); (2);
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148'); SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148');
SELECT cartodb_id, cartodb_id_0 from test; SELECT cartodb_id from test;
DROP TABLE test; DROP TABLE test;
-- Table with non unique and null cartodb_id -- Table with non unique and null cartodb_id
@@ -319,7 +319,7 @@ INSERT INTO test VALUES
(NULL), (NULL),
(2); (2);
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148'); SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148');
SELECT cartodb_id, cartodb_id_0 from test; SELECT cartodb_id from test;
DROP TABLE test; DROP TABLE test;
CREATE TABLE test ( CREATE TABLE test (
+17 -17
View File
@@ -33,8 +33,8 @@ SELECT 1
ERROR: CDB(_CDB_Rewrite_Table:22P02:invalid input syntax for integer: "nan"): CREATE TABLE public.t_0 AS SELECT cartodb_id::bigint ,NULL::geometry(Geometry,4326) AS the_geom,NULL::geometry(Geometry,3857) AS the_geom_webmercator FROM t ERROR: CDB(_CDB_Rewrite_Table:22P02:invalid input syntax for integer: "nan"): CREATE TABLE public.t_0 AS SELECT cartodb_id::bigint ,NULL::geometry(Geometry,4326) AS the_geom,NULL::geometry(Geometry,3857) AS the_geom_webmercator FROM t
DROP TABLE DROP TABLE
SELECT 1 SELECT 1
empty text cartodb_id cartodbfied fine ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE t ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id)
1|
DROP TABLE DROP TABLE
SELECT 1 SELECT 1
unsequenced cartodb_id cartodbfied fine unsequenced cartodb_id cartodbfied fine
@@ -86,30 +86,30 @@ Table with both the_geom and wkb_geometry #141 cartodbfied fine
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
INSERT 0 1 INSERT 0 1
ERROR: CDB(_CDB_Has_Usable_Primary_ID: multiple primary keys for table "many_colliding_columns" are not allowed): ALTER TABLE many_colliding_columns ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) ERROR: CDB(_CDB_Has_Usable_Primary_ID: not valid multiple primary keys for table "many_colliding_columns" are not allowed): ALTER TABLE many_colliding_columns ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id)
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
INSERT 0 4 INSERT 0 4
Table with null cartodb_id #148 cartodbfied fine ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id)
1|1 1
2|2 2
3|
4|3 3
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
INSERT 0 3 INSERT 0 3
Table with non unique cartodb_id #148 cartodbfied fine ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id)
1|1 1
2|2 2
3|2 2
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
INSERT 0 4 INSERT 0 4
Table with non unique and null cartodb_id #148 cartodbfied fine ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id)
1|1 1
2|2 2
3|
4|2 2
DROP TABLE DROP TABLE
CREATE TABLE CREATE TABLE
CREATE INDEX CREATE INDEX