diff --git a/Makefile b/Makefile index d5979e9..54a5833 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # cartodb/Makefile EXTENSION = cartodb -EXTVERSION = 0.17.1 +EXTVERSION = 0.18.2 SED = sed @@ -73,6 +73,9 @@ UPGRADABLE = \ 0.16.4 \ 0.17.0 \ 0.17.1 \ + 0.18.0 \ + 0.18.1 \ + 0.18.2 \ $(EXTVERSION)dev \ $(EXTVERSION)next \ $(END) diff --git a/NEWS.md b/NEWS.md index f94c031..6bac54f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,22 @@ +0.18.2 (2016-10-20) +------------------- + +* Fix: cleanup inconsistent position of `username` column in analysis catalog after upgrades + [#285](https://github.com/cartodb/cartodb-postgresql/pull/285) + +0.18.1 (2016-10-19) +------------------- + +* Increase analysis limit factor to 2 [#284](https://github.com/CartoDB/cartodb-postgresql/pull/284) + +0.18.0 (2016-10-17) +------------------- + +* Fix: exclude NULL geometries when creating Overviews #269 +* Function to check analysis tables limits #279 +* Exclude analysis cache tables from the quota #281 + + 0.17.1 (2016-08-16) ------------------- diff --git a/scripts-available/CDB_AnalysisCatalog.sql b/scripts-available/CDB_AnalysisCatalog.sql index 905a821..b670d21 100644 --- a/scripts-available/CDB_AnalysisCatalog.sql +++ b/scripts-available/CDB_AnalysisCatalog.sql @@ -1,8 +1,6 @@ -- Table to register analysis nodes from https://github.com/cartodb/camshaft CREATE TABLE IF NOT EXISTS cartodb.cdb_analysis_catalog ( - -- useful for multi account deployments - username text, -- md5 hex hash node_id char(40) CONSTRAINT cdb_analysis_catalog_pkey PRIMARY KEY, -- being json allows to do queries like analysis_def->>'type' = 'buffer' @@ -28,7 +26,9 @@ cartodb.cdb_analysis_catalog ( -- store error message for failures last_error_message text, -- cached tables involved in the analysis - cache_tables regclass[] NOT NULL DEFAULT '{}' + cache_tables regclass[] NOT NULL DEFAULT '{}', + -- useful for multi account deployments + username text ); -- This can only be called from an SQL script executed by CREATE EXTENSION @@ -38,14 +38,9 @@ BEGIN END $$; -DO $$ - BEGIN - BEGIN - ALTER TABLE cartodb.cdb_analysis_catalog ADD COLUMN username text; - EXCEPTION - WHEN duplicate_column THEN END; - END; -$$; +-- Migrations to add new columns from old versions. +-- IMPORTANT: Those columns will be added in order of creation. To be consistent +-- in column order, ensure that new columns are added at the end and in the same order. DO $$ BEGIN @@ -73,3 +68,28 @@ DO $$ WHEN duplicate_column THEN END; END; $$; + +DO $$ + BEGIN + BEGIN + ALTER TABLE cartodb.cdb_analysis_catalog ADD COLUMN username text; + EXCEPTION + WHEN duplicate_column THEN END; + END; +$$; + +-- We want the "username" column to be moved to the last position if it was on a position from other versions +-- see https://github.com/CartoDB/cartodb-postgresql/issues/276 +DO LANGUAGE 'plpgsql' $$ + DECLARE + column_index int; + BEGIN + SELECT ordinal_position FROM information_schema.columns WHERE table_name='cdb_analysis_catalog' AND table_schema='cartodb' AND column_name='username' INTO column_index; + IF column_index = 1 OR column_index = 10 THEN + ALTER TABLE cartodb.cdb_analysis_catalog ADD COLUMN username_final text; + UPDATE cartodb.cdb_analysis_catalog SET username_final = username; + ALTER TABLE cartodb.cdb_analysis_catalog DROP COLUMN username; + ALTER TABLE cartodb.cdb_analysis_catalog RENAME COLUMN username_final TO username; + END IF; + END; +$$; diff --git a/scripts-available/CDB_AnalysisCheck.sql b/scripts-available/CDB_AnalysisCheck.sql index c8dddf3..1aab236 100644 --- a/scripts-available/CDB_AnalysisCheck.sql +++ b/scripts-available/CDB_AnalysisCheck.sql @@ -21,7 +21,7 @@ BEGIN factor := _CDB_GetConfAnalysisQuotaFactor(); -- With a default value IF factor IS NULL THEN - factor := 0.2; + factor := 2; END IF; RETURN factor; END; @@ -39,7 +39,7 @@ $$ DECLARE schema_name TEXT; user_name TEXT; - qmax int8; + nominal_quota int8; cache_size float8; BEGIN -- We rely on the search_path to determine the user's schema and @@ -53,8 +53,8 @@ BEGIN -- At the moment we're not using the provided table_name. SELECT current_schema() INTO schema_name; - EXECUTE FORMAT('SELECT %I._CDB_UserQuotaInBytes();', schema_name) INTO qmax; - IF qmax*_CDB_AnalysisQuotaFactor() < _CDB_AnalysisDataSize(schema_name) THEN + EXECUTE FORMAT('SELECT %I._CDB_UserQuotaInBytes();', schema_name) INTO nominal_quota; + IF nominal_quota*_CDB_AnalysisQuotaFactor() < _CDB_AnalysisDataSize(schema_name) THEN -- The limit is defined by a factor applied to the total space quota for the user RAISE EXCEPTION 'Analysis cache space limits exceeded'; END IF; diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index 27743f1..d2ab5fd 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -687,6 +687,7 @@ AS $$ Floor(ST_Y(f.the_geom_webmercator)/%2$s)::int AS gy, MIN(cartodb_id) AS cartodb_id FROM %1$s f + WHERE f.the_geom_webmercator IS NOT NULL GROUP BY gx, gy ) SELECT %6$s FROM clusters