Fix: Cartodbfication failed with existing PK
This fixes #174 When a unique index and a primary key contraint existed for a column named cartodb_id cartodbfy tried to add another PK constraint
This commit is contained in:
@@ -504,7 +504,7 @@ BEGIN
|
||||
IF rec.atttypid IN (20,21,23) THEN
|
||||
|
||||
-- And it's a unique primary key! Done!
|
||||
IF rec.indisprimary AND rec.indisunique AND rec.attnotnull THEN
|
||||
IF (rec.indisprimary OR rec.indisunique) AND rec.attnotnull THEN
|
||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('found good ''%s''', const.pkey);
|
||||
RETURN true;
|
||||
|
||||
|
||||
@@ -319,6 +319,20 @@ SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_i
|
||||
SELECT cartodb_id, cartodb_id_0 from test;
|
||||
DROP TABLE test;
|
||||
|
||||
CREATE TABLE test (
|
||||
cartodb_id integer
|
||||
);
|
||||
CREATE UNIQUE INDEX "test_cartodb_id_key" ON test (cartodb_id);
|
||||
CREATE UNIQUE INDEX "test_cartodb_id_pkey" ON test (cartodb_id);
|
||||
ALTER TABLE test ADD CONSTRAINT "test_pkey" PRIMARY KEY USING INDEX test_cartodb_id_pkey;
|
||||
INSERT INTO test VALUES
|
||||
(1),
|
||||
(2),
|
||||
(3);
|
||||
SELECT CDB_CartodbfyTableCheck('test', 'Table with primary key and unique index on it #174');
|
||||
SELECT cartodb_id from test;
|
||||
DROP TABLE test;
|
||||
|
||||
CREATE TABLE test (
|
||||
name varchar,
|
||||
"first.value" integer,
|
||||
|
||||
@@ -103,6 +103,16 @@ Table with non unique and null cartodb_id #148 cartodbfied fine
|
||||
4|2
|
||||
DROP TABLE
|
||||
CREATE TABLE
|
||||
CREATE INDEX
|
||||
CREATE INDEX
|
||||
ALTER TABLE
|
||||
INSERT 0 3
|
||||
Table with primary key and unique index on it #174 cartodbfied fine
|
||||
1
|
||||
2
|
||||
3
|
||||
DROP TABLE
|
||||
CREATE TABLE
|
||||
INSERT 0 2
|
||||
Table with dots in name columns (cartodb #6114) cartodbfied fine
|
||||
one|1
|
||||
|
||||
Reference in New Issue
Block a user