Do not allow cartodbfying tables while no user quota is set

Closes #17
Updates tests
This commit is contained in:
Sandro Santilli 2014-05-12 13:07:47 +02:00
parent e6b02de9aa
commit f98071cdac
7 changed files with 28 additions and 3 deletions

View File

@ -10,7 +10,13 @@ EXCEPTION
RETURNS void AS '' LANGUAGE 'sql';
END;
$$ LANGUAGE 'plpgsql';
--SELECT tmp();
-- Set user quota to infinite
SELECT CDB_SetUserQuotaInBytes(0);
cdb_setuserquotainbytes
-------------------------
0
(1 row)
create schema c;
CREATE USER cartodb_postgresql_unpriv_user;
GRANT ALL ON SCHEMA c to cartodb_postgresql_unpriv_user;
@ -207,3 +213,4 @@ select count(*) from CDB_TableMetadata;
(1 row)
DROP USER cartodb_postgresql_unpriv_user;
DROP FUNCTION _CDB_UserQuotaInBytes();

View File

@ -40,6 +40,13 @@ DECLARE
exists_geom_cols BOOLEAN[];
BEGIN
-- TODO: Check that user quota is set ?
BEGIN
PERFORM public._CDB_UserQuotaInBytes();
EXCEPTION WHEN undefined_function THEN
RAISE EXCEPTION 'Please set user quota before cartodbfying tables.';
END;
-- Drop cartodb triggers (might prevent changing columns)
-- "track_updates"

View File

@ -12,8 +12,8 @@ EXCEPTION
END;
$$ LANGUAGE 'plpgsql';
--SELECT tmp();
-- Set user quota to infinite
SELECT CDB_SetUserQuotaInBytes(0);
create schema c;
@ -121,3 +121,4 @@ drop schema c cascade;
select count(*) from CDB_TableMetadata;
DROP USER cartodb_postgresql_unpriv_user;
DROP FUNCTION _CDB_UserQuotaInBytes();

View File

@ -132,6 +132,8 @@ LANGUAGE 'plpgsql';
-- table with single non-geometrical column
CREATE TABLE t AS SELECT 1::int as a;
SELECT CDB_CartodbfyTable('t'); -- should fail
SELECT CDB_SetUserQuotaInBytes(0); -- Set user quota to infinite
SELECT CDB_CartodbfyTableCheck('t', 'single non-geometrical column');
DROP TABLE t;
@ -171,3 +173,4 @@ DROP TABLE t;
-- TODO: table with existing custom-triggered the_geom
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
DROP FUNCTION _CDB_UserQuotaInBytes();

View File

@ -1,6 +1,8 @@
SET
CREATE FUNCTION
SELECT 1
ERROR: Please set user quota before cartodbfying tables.
0
single non-geometrical column cartodbfied fine
DROP TABLE
SELECT 1
@ -24,3 +26,4 @@ trigger-protected the_geom cartodbfied fine
extent|BOX(1 1,2 2)
DROP TABLE
DROP FUNCTION
DROP FUNCTION

View File

@ -7,6 +7,7 @@ CREATE TRIGGER test_quota BEFORE UPDATE OR INSERT ON big
EXECUTE PROCEDURE CDB_CheckQuota(1,1);
INSERT INTO big VALUES (1); -- allowed, check runs before
INSERT INTO big VALUES (1); -- disallowed, quota exceeds before
SELECT CDB_SetUserQuotaInBytes(0);
SELECT CDB_CartodbfyTable('big');
INSERT INTO big SELECT generate_series(1,1024);
SELECT CDB_SetUserQuotaInBytes(8);
@ -15,3 +16,4 @@ SELECT CDB_SetUserQuotaInBytes(0);
INSERT INTO big VALUES (1);
DROP TABLE big;
set client_min_messages to NOTICE;
DROP FUNCTION _CDB_UserQuotaInBytes();

View File

@ -3,6 +3,7 @@ CREATE TABLE
CREATE TRIGGER
INSERT 0 1
ERROR: Quota exceeded by 3.9990234375KB
0
INSERT 0 1024
0
@ -11,3 +12,4 @@ ERROR: Quota exceeded by 103.9921875KB
INSERT 0 1
DROP TABLE
SET
DROP FUNCTION