Merge pull request #78 from CartoDB/new_cartodbfy
[wip] New cartodbfy function (overwrites CDB_CartodbfyTable)
This commit is contained in:
commit
74e6807c2f
3
Makefile
3
Makefile
@ -1,7 +1,7 @@
|
||||
# cartodb/Makefile
|
||||
|
||||
EXTENSION = cartodb
|
||||
EXTVERSION = 0.8.3
|
||||
EXTVERSION = 0.9.0
|
||||
|
||||
SED = sed
|
||||
|
||||
@ -42,6 +42,7 @@ UPGRADABLE = \
|
||||
0.8.0 \
|
||||
0.8.1 \
|
||||
0.8.2 \
|
||||
0.9.0 \
|
||||
$(EXTVERSION)dev \
|
||||
$(EXTVERSION)next \
|
||||
$(END)
|
||||
|
17
NEWS.md
17
NEWS.md
@ -1,4 +1,19 @@
|
||||
0.8.3 (2015-mm-dd)
|
||||
0.9.0 (2015-08-19)
|
||||
------------------
|
||||
* Re-implementation of `CDB_CartodbfyTable` functions
|
||||
- The signature of the main function changes to
|
||||
```
|
||||
FUNCTION CDB_CartodbfyTable(destschema TEXT, reloid REGCLASS)
|
||||
RETURNS REGCLASS
|
||||
```
|
||||
- The `destschema` does not need to match the origin schema of `reloid`
|
||||
- It returns the `regclass` of the cartodbfy'ed table, if it needs to be rewritten.
|
||||
- There are many optimizations
|
||||
- The columns `created_at` and `updated_at` will no longer be added
|
||||
* Fix for CDB_UserDataSize failing due `ERROR: relation "*" does not exist.` #110
|
||||
* Review test to validate permissions in public tables [#112](https://github.com/CartoDB/cartodb-postgresql/pull/112)
|
||||
|
||||
0.8.3 (2015-08-14)
|
||||
------------------
|
||||
* Fixes CDB_UserDataSize failing due `ERROR: relation "*" does not exist.` [#108](https://github.com/CartoDB/cartodb-postgresql/issues/108)
|
||||
|
||||
|
@ -25,6 +25,8 @@ SELECT CDB_SetUserQuotaInBytes('c', 0);
|
||||
0
|
||||
(1 row)
|
||||
|
||||
DROP USER IF EXISTS cartodb_postgresql_unpriv_user;
|
||||
NOTICE: role "cartodb_postgresql_unpriv_user" does not exist, skipping
|
||||
CREATE USER cartodb_postgresql_unpriv_user;
|
||||
GRANT ALL ON SCHEMA c to cartodb_postgresql_unpriv_user;
|
||||
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
@ -36,7 +38,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select 1 as i INTO c.t3;
|
||||
NOTICE: trigger "track_updates" for table "c.t3" does not exist, skipping
|
||||
NOTICE: trigger "update_the_geom_webmercator_trigger" for table "c.t3" does not exist, skipping
|
||||
NOTICE: trigger "update_updated_at_trigger" for table "c.t3" does not exist, skipping
|
||||
NOTICE: trigger "test_quota" for table "c.t3" does not exist, skipping
|
||||
NOTICE: trigger "test_quota_per_row" for table "c.t3" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||
@ -45,17 +46,6 @@ NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
|
||||
NOTICE: cdb_invalidate_varnish(c.t3) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i
|
||||
from c.t3;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator | i
|
||||
------------+-----+------+----------+----------------------+---
|
||||
1 | t | t | | | 1
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -72,28 +62,14 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select 1 as cartodb_id INTO c.t4;
|
||||
NOTICE: trigger "track_updates" for table "c.t4" does not exist, skipping
|
||||
NOTICE: trigger "update_the_geom_webmercator_trigger" for table "c.t4" does not exist, skipping
|
||||
NOTICE: trigger "update_updated_at_trigger" for table "c.t4" does not exist, skipping
|
||||
NOTICE: trigger "test_quota" for table "c.t4" does not exist, skipping
|
||||
NOTICE: trigger "test_quota_per_row" for table "c.t4" does not exist, skipping
|
||||
NOTICE: Column cartodb_id already exists
|
||||
NOTICE: Existing cartodb_id field does not have an associated sequence, renaming
|
||||
NOTICE: Trying to recover data from _cartodb_id0 column
|
||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
|
||||
NOTICE: cdb_invalidate_varnish(c.t4) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator
|
||||
from c.t4;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator
|
||||
------------+-----+------+----------+----------------------
|
||||
1 | t | t | |
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -115,27 +91,12 @@ select pg_sleep(.1);
|
||||
(1 row)
|
||||
|
||||
alter table c.t3 rename column the_geom_webmercator to webmerc;
|
||||
NOTICE: Column cartodb_id already exists
|
||||
NOTICE: Column created_at already exists
|
||||
NOTICE: Column updated_at already exists
|
||||
NOTICE: Column the_geom already exists
|
||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
|
||||
NOTICE: cdb_invalidate_varnish(c.t3) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc
|
||||
from c.t3;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator | i | webmerc
|
||||
------------+-----+------+----------+----------------------+---+---------
|
||||
1 | t | t | | | 1 |
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -154,27 +115,12 @@ select pg_sleep(.1);
|
||||
(1 row)
|
||||
|
||||
alter table c.t3 rename column the_geom_webmercator to webmerc2;
|
||||
NOTICE: Column cartodb_id already exists
|
||||
NOTICE: Column created_at already exists
|
||||
NOTICE: Column updated_at already exists
|
||||
NOTICE: Column the_geom already exists
|
||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
|
||||
NOTICE: cdb_invalidate_varnish(c.t3) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2
|
||||
from c.t3;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator | i | webmerc | webmerc2
|
||||
------------+-----+------+----------+----------------------+---+---------+----------
|
||||
1 | t | t | | | 1 | |
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -196,27 +142,12 @@ select pg_sleep(.1);
|
||||
(1 row)
|
||||
|
||||
alter table c.t3 drop column the_geom_webmercator;
|
||||
NOTICE: Column cartodb_id already exists
|
||||
NOTICE: Column created_at already exists
|
||||
NOTICE: Column updated_at already exists
|
||||
NOTICE: Column the_geom already exists
|
||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
|
||||
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
|
||||
NOTICE: cdb_invalidate_varnish(c.t3) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2
|
||||
from c.t3;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator | i | webmerc | webmerc2
|
||||
------------+-----+------+----------+----------------------+---+---------+----------
|
||||
1 | t | t | | | 1 | |
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -239,17 +170,6 @@ select pg_sleep(.1);
|
||||
|
||||
alter table c.t3 add column id2 int;
|
||||
NOTICE: cdb_invalidate_varnish(c.t3) called
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2, id2
|
||||
from c.t3;
|
||||
cartodb_id | c=u | u<1s | the_geom | the_geom_webmercator | i | webmerc | webmerc2 | id2
|
||||
------------+-----+------+----------+----------------------+---+---------+----------+-----
|
||||
1 | t | t | | | 1 | | |
|
||||
(1 row)
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -272,5 +192,6 @@ select count(*) from CDB_TableMetadata;
|
||||
0
|
||||
(1 row)
|
||||
|
||||
DROP USER cartodb_postgresql_unpriv_user;
|
||||
DROP OWNED BY cartodb_postgresql_unpriv_user;
|
||||
DROP ROLE cartodb_postgresql_unpriv_user;
|
||||
DROP FUNCTION _CDB_UserQuotaInBytes();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,17 +4,23 @@ CREATE OR REPLACE FUNCTION cartodb.cdb_handle_create_table ()
|
||||
RETURNS event_trigger SECURITY DEFINER LANGUAGE plpgsql AS $$
|
||||
DECLARE
|
||||
event_info RECORD;
|
||||
rel_namespace TEXT;
|
||||
rel RECORD;
|
||||
newtable REGCLASS;
|
||||
BEGIN
|
||||
event_info := schema_triggers.get_relation_create_eventinfo();
|
||||
|
||||
-- We're only interested in real relations
|
||||
IF (event_info.new).relkind != 'r' THEN RETURN; END IF;
|
||||
|
||||
SELECT nspname FROM pg_namespace WHERE oid=(event_info.new).relnamespace INTO rel_namespace;
|
||||
SELECT c.relname, c.relnamespace, c.relkind, n.nspname
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n
|
||||
ON c.relnamespace = n.oid
|
||||
WHERE c.oid = event_info.relation
|
||||
INTO rel;
|
||||
|
||||
RAISE DEBUG 'Relation % of kind % created in table % namespace % (oid %)',
|
||||
event_info.relation, (event_info.new).relkind, (event_info.new).relname::TEXT, rel_namespace, (event_info.new).relnamespace;
|
||||
event_info.relation, rel.relkind, rel.relname, rel.nspname, rel.relnamespace;
|
||||
|
||||
-- We don't want to react to alters triggered by superuser,
|
||||
IF current_setting('is_superuser') = 'on' THEN
|
||||
@ -25,15 +31,15 @@ BEGIN
|
||||
PERFORM cartodb.cdb_disable_ddl_hooks();
|
||||
|
||||
-- CDB_CartodbfyTable must not create tables, or infinite loop will happen
|
||||
PERFORM cartodb.CDB_CartodbfyTable(rel_namespace, event_info.relation);
|
||||
newtable := cartodb.CDB_CartodbfyTable(rel.nspname, event_info.relation);
|
||||
|
||||
PERFORM cartodb.cdb_enable_ddl_hooks();
|
||||
|
||||
RAISE DEBUG 'Inserting into cartodb.CDB_TableMetadata';
|
||||
|
||||
-- Add entry to CDB_TableMetadata (should CartodbfyTable do this?)
|
||||
INSERT INTO cartodb.CDB_TableMetadata(tabname,updated_at)
|
||||
VALUES (event_info.relation, now());
|
||||
INSERT INTO cartodb.CDB_TableMetadata(tabname, updated_at)
|
||||
VALUES (newtable, now());
|
||||
|
||||
END; $$;
|
||||
-- }
|
||||
@ -66,14 +72,19 @@ RETURNS event_trigger SECURITY DEFINER LANGUAGE plpgsql AS $$
|
||||
DECLARE
|
||||
event_info RECORD;
|
||||
rel RECORD;
|
||||
rel_namespace TEXT;
|
||||
newtable REGCLASS;
|
||||
BEGIN
|
||||
event_info := schema_triggers.get_column_alter_eventinfo();
|
||||
|
||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||
SELECT c.relname, c.relnamespace, c.relkind, n.nspname
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n
|
||||
ON c.relnamespace = n.oid
|
||||
WHERE c.oid = event_info.relation
|
||||
INTO rel;
|
||||
|
||||
RAISE DEBUG 'Column % altered by % (superuser? %) in relation % of kind %',
|
||||
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||
(event_info.old).attname, current_user, current_setting('is_superuser'), rel.relname, rel.relkind;
|
||||
|
||||
-- We're only interested in real relations
|
||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||
@ -84,16 +95,14 @@ BEGIN
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
SELECT nspname FROM pg_namespace WHERE oid = rel.relnamespace INTO rel_namespace;
|
||||
|
||||
PERFORM cartodb.cdb_disable_ddl_hooks();
|
||||
|
||||
PERFORM cartodb.CDB_CartodbfyTable(rel_namespace, event_info.relation);
|
||||
newtable := cartodb.CDB_CartodbfyTable(rel.nspname, event_info.relation);
|
||||
|
||||
PERFORM cartodb.cdb_enable_ddl_hooks();
|
||||
|
||||
-- update CDB_TableMetadata.updated_at (should invalidate varnish)
|
||||
UPDATE cartodb.CDB_TableMetadata SET updated_at = NOW()
|
||||
UPDATE cartodb.CDB_TableMetadata SET updated_at = NOW(), tabname = newtable
|
||||
WHERE tabname = event_info.relation;
|
||||
|
||||
END; $$;
|
||||
@ -106,14 +115,19 @@ RETURNS event_trigger SECURITY DEFINER LANGUAGE plpgsql AS $$
|
||||
DECLARE
|
||||
event_info RECORD;
|
||||
rel RECORD;
|
||||
rel_namespace TEXT;
|
||||
newtable REGCLASS;
|
||||
BEGIN
|
||||
event_info := schema_triggers.get_column_drop_eventinfo();
|
||||
|
||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||
SELECT c.relname, c.relnamespace, c.relkind, n.nspname
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n
|
||||
ON c.relnamespace = n.oid
|
||||
WHERE c.oid = event_info.relation
|
||||
INTO rel;
|
||||
|
||||
RAISE DEBUG 'Column % drop by % (superuser? %) in relation % of kind %',
|
||||
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||
(event_info.old).attname, current_user, current_setting('is_superuser'), rel.relname, rel.relkind;
|
||||
|
||||
-- We're only interested in real relations
|
||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||
@ -124,16 +138,15 @@ BEGIN
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
SELECT nspname FROM pg_namespace WHERE oid = rel.relnamespace INTO rel_namespace;
|
||||
|
||||
PERFORM cartodb.cdb_disable_ddl_hooks();
|
||||
|
||||
PERFORM cartodb.CDB_CartodbfyTable(rel_namespace, event_info.relation);
|
||||
newtable := cartodb.CDB_CartodbfyTable(rel.nspname, event_info.relation);
|
||||
|
||||
PERFORM cartodb.cdb_enable_ddl_hooks();
|
||||
|
||||
-- update CDB_TableMetadata.updated_at (should invalidate varnish)
|
||||
UPDATE cartodb.CDB_TableMetadata SET updated_at = NOW()
|
||||
UPDATE cartodb.CDB_TableMetadata SET updated_at = NOW(), tabname = newtable
|
||||
WHERE tabname = event_info.relation;
|
||||
|
||||
END; $$;
|
||||
@ -149,10 +162,15 @@ DECLARE
|
||||
BEGIN
|
||||
event_info := schema_triggers.get_column_add_eventinfo();
|
||||
|
||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||
SELECT c.relname, c.relnamespace, c.relkind, n.nspname
|
||||
FROM pg_class c
|
||||
JOIN pg_namespace n
|
||||
ON c.relnamespace = n.oid
|
||||
WHERE c.oid = event_info.relation
|
||||
INTO rel;
|
||||
|
||||
RAISE DEBUG 'Column % added by % (superuser? %) in relation % of kind %',
|
||||
(event_info.new).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||
(event_info.new).attname, current_user, current_setting('is_superuser'), rel.relname, rel.relkind;
|
||||
|
||||
-- We're only interested in real relations
|
||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||
|
@ -10,6 +10,7 @@ create schema c;
|
||||
|
||||
SELECT CDB_SetUserQuotaInBytes('c', 0);
|
||||
|
||||
DROP USER IF EXISTS cartodb_postgresql_unpriv_user;
|
||||
CREATE USER cartodb_postgresql_unpriv_user;
|
||||
GRANT ALL ON SCHEMA c to cartodb_postgresql_unpriv_user;
|
||||
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
@ -21,13 +22,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select 1 as i INTO c.t3;
|
||||
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i
|
||||
from c.t3;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -38,11 +32,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
-- Table with cartodb_id field, see
|
||||
-- http://github.com/CartoDB/cartodb-postgresql/issues/32
|
||||
select 1 as cartodb_id INTO c.t4;
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator
|
||||
from c.t4;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
@ -58,13 +47,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select pg_sleep(.1);
|
||||
alter table c.t3 rename column the_geom_webmercator to webmerc;
|
||||
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc
|
||||
from c.t3;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -75,13 +57,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select pg_sleep(.1);
|
||||
alter table c.t3 rename column the_geom_webmercator to webmerc2;
|
||||
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2
|
||||
from c.t3;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -95,13 +70,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select pg_sleep(.1);
|
||||
alter table c.t3 drop column the_geom_webmercator;
|
||||
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2
|
||||
from c.t3;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -115,13 +83,6 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
|
||||
select pg_sleep(.1);
|
||||
alter table c.t3 add column id2 int;
|
||||
|
||||
select
|
||||
cartodb_id, created_at=updated_at as "c=u",
|
||||
NOW() - updated_at < '1 secs' as "u<1s",
|
||||
the_geom, the_geom_webmercator,
|
||||
i, webmerc, webmerc2, id2
|
||||
from c.t3;
|
||||
|
||||
RESET SESSION AUTHORIZATION;
|
||||
select
|
||||
tabname::text,
|
||||
@ -136,5 +97,6 @@ RESET SESSION AUTHORIZATION;
|
||||
drop schema c cascade;
|
||||
select count(*) from CDB_TableMetadata;
|
||||
|
||||
DROP USER cartodb_postgresql_unpriv_user;
|
||||
DROP OWNED BY cartodb_postgresql_unpriv_user;
|
||||
DROP ROLE cartodb_postgresql_unpriv_user;
|
||||
DROP FUNCTION _CDB_UserQuotaInBytes();
|
||||
|
@ -12,6 +12,7 @@ DECLARE
|
||||
tmp INTEGER;
|
||||
ogc_geom geometry_columns; -- old the_geom record in geometry_columns
|
||||
ogc_merc geometry_columns; -- old the_geom_webmercator record in geometry_columns
|
||||
tabtext TEXT;
|
||||
BEGIN
|
||||
|
||||
-- Save current constraints on geometry columns, if any
|
||||
@ -30,24 +31,17 @@ BEGIN
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
tabtext := Format('%s.%s','public',tabname);
|
||||
RAISE NOTICE 'CARTODBFYING % !!!!', tabtext;
|
||||
PERFORM CDB_CartodbfyTable('public', tabname);
|
||||
tabname := tabtext::regclass;
|
||||
|
||||
sql := 'INSERT INTO ' || tabname::text || '(the_geom) values ( CDB_LatLng(2,1) ) RETURNING cartodb_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;
|
||||
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
|
||||
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));
|
||||
@ -84,7 +78,7 @@ BEGIN
|
||||
rec.f_geometry_column, rec.srid, rec.expsrid;
|
||||
END IF;
|
||||
-- Check TYPE constraint didn't change
|
||||
IF rec.type != rec.exptype THEN
|
||||
IF (rec.type != 'GEOMETRY') AND (rec.type != 'POINT') THEN
|
||||
RAISE EXCEPTION 'type of % in geometry_columns is %, expected %',
|
||||
rec.f_geometry_column, rec.type, rec.exptype;
|
||||
END IF;
|
||||
@ -115,10 +109,10 @@ BEGIN
|
||||
-- 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' )
|
||||
( 'cartodb_id' )
|
||||
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';
|
||||
RAISE EXCEPTION 'cartodb_id is missing not-null constraint';
|
||||
END IF;
|
||||
|
||||
-- Cleanup
|
||||
@ -170,29 +164,19 @@ SELECT CDB_CartodbfyTableCheck('t', 'trigger-protected the_geom');
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM 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;
|
||||
-- INFO: disabled because cartodbfy does not longer consider text columns for primary ID
|
||||
-- -- table with existing cartodb_id field of type text
|
||||
-- CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
||||
-- SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
||||
-- select cartodb_id/2 FROM t;
|
||||
-- DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type text
|
||||
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
||||
select cartodb_id/2 FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type text not casting
|
||||
CREATE TABLE t AS SELECT 'nan' as cartodb_id;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'uncasting text cartodb_id');
|
||||
select cartodb_id,_cartodb_id0 FROM t;
|
||||
DROP TABLE t;
|
||||
-- INFO: disabled because cartodbfy does not longer consider text columns for primary ID
|
||||
-- -- table with existing cartodb_id field of type text not casting
|
||||
-- CREATE TABLE t AS SELECT 'nan' as cartodb_id;
|
||||
-- SELECT CDB_CartodbfyTableCheck('t', 'uncasting text cartodb_id');
|
||||
-- select cartodb_id,_cartodb_id0 FROM t;
|
||||
-- DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type int4 not sequenced
|
||||
CREATE TABLE t AS SELECT 1::int4 as cartodb_id;
|
||||
@ -208,22 +192,6 @@ 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
|
||||
-- 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
|
||||
|
||||
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
|
||||
|
@ -2,8 +2,8 @@ SET
|
||||
CREATE FUNCTION
|
||||
SELECT 1
|
||||
ERROR: Please set user quota before cartodbfying tables.
|
||||
CONTEXT: SQL statement "SELECT cartodb._CDB_check_prerequisites(schema_name, reloid)"
|
||||
PL/pgSQL function cdb_cartodbfytable(text,regclass) line 7 at PERFORM
|
||||
CONTEXT: SQL statement "SELECT cartodb._CDB_check_prerequisites(destschema, reloid)"
|
||||
PL/pgSQL function cdb_cartodbfytable(text,regclass) line 21 at PERFORM
|
||||
0
|
||||
single non-geometrical column cartodbfied fine
|
||||
DROP TABLE
|
||||
@ -28,21 +28,6 @@ trigger-protected the_geom cartodbfied fine
|
||||
extent|BOX(1 1,2 2)
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
text timestamps cartodbfied fine
|
||||
0|0
|
||||
CREATE VIEW
|
||||
cartodbfied with view cartodbfied fine
|
||||
DROP VIEW
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
text cartodb_id cartodbfied fine
|
||||
5
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
uncasting text cartodb_id cartodbfied fine
|
||||
1|nan
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
unsequenced cartodb_id cartodbfied fine
|
||||
1
|
||||
DROP TABLE
|
||||
@ -50,8 +35,5 @@ CREATE TABLE
|
||||
cartodb_id serial primary key cartodbfied fine
|
||||
t_pkey|cartodb_id
|
||||
DROP TABLE
|
||||
CREATE TABLE
|
||||
null geom and timestamp values cartodbfied fine
|
||||
DROP TABLE
|
||||
DROP FUNCTION
|
||||
DROP FUNCTION
|
||||
|
@ -7,21 +7,21 @@ CREATE TABLE big(a int);
|
||||
CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
|
||||
EXECUTE PROCEDURE CDB_CheckQuota(1, 1, 'public');
|
||||
INSERT INTO big VALUES (1); -- allowed, check runs before
|
||||
INSERT INTO big VALUES (1); -- disallowed, quota exceeds before
|
||||
INSERT INTO big VALUES (2); -- disallowed, quota exceeds before
|
||||
SELECT CDB_SetUserQuotaInBytes(0);
|
||||
SELECT CDB_CartodbfyTable('big');
|
||||
INSERT INTO big SELECT generate_series(1,2048);
|
||||
INSERT INTO big SELECT generate_series(1,2048);
|
||||
INSERT INTO big SELECT generate_series(1,2048);
|
||||
INSERT INTO big SELECT generate_series(2049,4096);
|
||||
INSERT INTO big SELECT generate_series(4097,6144);
|
||||
INSERT INTO big SELECT generate_series(6145,8192);
|
||||
-- Test for #108: https://github.com/CartoDB/cartodb-postgresql/issues/108
|
||||
SELECT CDB_UserDataSize();
|
||||
SELECT cartodb._CDB_total_relation_size('public', 'big');
|
||||
SELECT cartodb._CDB_total_relation_size('public', 'nonexistent_table_name');
|
||||
-- END Test for #108
|
||||
SELECT CDB_SetUserQuotaInBytes(2);
|
||||
INSERT INTO big VALUES (1);
|
||||
INSERT INTO big VALUES (8193);
|
||||
SELECT CDB_SetUserQuotaInBytes(0);
|
||||
INSERT INTO big VALUES (1);
|
||||
INSERT INTO big VALUES (8194);
|
||||
DROP TABLE big;
|
||||
set client_min_messages to NOTICE;
|
||||
DROP FUNCTION _CDB_UserQuotaInBytes();
|
||||
|
@ -4,15 +4,15 @@ CREATE TRIGGER
|
||||
INSERT 0 1
|
||||
ERROR: Quota exceeded by 3.9990234375KB
|
||||
0
|
||||
|
||||
big
|
||||
INSERT 0 2048
|
||||
INSERT 0 2048
|
||||
INSERT 0 2048
|
||||
581632
|
||||
1163264
|
||||
454656
|
||||
909312
|
||||
0
|
||||
2
|
||||
ERROR: Quota exceeded by 567.998046875KB
|
||||
ERROR: Quota exceeded by 443.998046875KB
|
||||
0
|
||||
INSERT 0 1
|
||||
DROP TABLE
|
||||
|
Loading…
Reference in New Issue
Block a user