Do not add unique index on cartodb_id if already a primary key

Closes #38
This commit is contained in:
Sandro Santilli 2014-06-11 19:21:19 +02:00
parent afcc2498c8
commit bc0966c46e
4 changed files with 17 additions and 1 deletions

4
NEWS
View File

@ -7,6 +7,10 @@ Enhancements:
- Drop useless DEFAULT specification in plpgsql variable declarations - Drop useless DEFAULT specification in plpgsql variable declarations
- List plpythonu requirement first, so get pg_catalog scanned before public - 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 0.2.0 - 2014-06-09
------------------ ------------------

View File

@ -111,7 +111,7 @@ BEGIN
AND a.attrelid = reloid AND a.attrelid = reloid
AND NOT a.attisdropped AND NOT a.attisdropped
AND a.attname = 'cartodb_id' AND a.attname = 'cartodb_id'
AND c.contype = 'u' ) -- unique AND c.contype IN ( 'u', 'p' ) ) -- unique or pkey
THEN THEN
sql := sql || ', ADD unique(cartodb_id)'; sql := sql || ', ADD unique(cartodb_id)';
END IF; END IF;

View File

@ -200,6 +200,14 @@ SELECT CDB_CartodbfyTableCheck('t', 'unsequenced cartodb_id');
select cartodb_id FROM t; select cartodb_id FROM t;
DROP TABLE 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 -- table with existing the_geom and created_at and containing null values
-- Really, a test for surviving an longstanding PostgreSQL bug: -- Really, a test for surviving an longstanding PostgreSQL bug:
-- http://www.postgresql.org/message-id/20140530143150.GA11051@localhost -- http://www.postgresql.org/message-id/20140530143150.GA11051@localhost

View File

@ -45,6 +45,10 @@ unsequenced cartodb_id cartodbfied fine
1 1
DROP TABLE DROP TABLE
CREATE 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 null geom and timestamp values cartodbfied fine
DROP TABLE DROP TABLE
DROP FUNCTION DROP FUNCTION