[postgis-tickets] r16847 - Revise postgis_extensions_upgrade to repackage raster if it finds it unpackaged. Revise unpackage notice to say to give instruction to call the postgis_extensions_upgrade function and repackage.

Regina Obe lr at pcorp.us
Thu Sep 27 02:50:36 PDT 2018


Author: robe
Date: 2018-09-27 14:50:36 -0700 (Thu, 27 Sep 2018)
New Revision: 16847

Modified:
   trunk/extensions/postgis/unpackage_raster_if_needed.sql
   trunk/postgis/postgis.sql.in
Log:
Revise postgis_extensions_upgrade to repackage raster if it finds it unpackaged.  Revise unpackage notice to say to give instruction to call the postgis_extensions_upgrade function and repackage.

Modified: trunk/extensions/postgis/unpackage_raster_if_needed.sql
===================================================================
--- trunk/extensions/postgis/unpackage_raster_if_needed.sql	2018-09-27 13:34:38 UTC (rev 16846)
+++ trunk/extensions/postgis/unpackage_raster_if_needed.sql	2018-09-27 21:50:36 UTC (rev 16847)
@@ -15,8 +15,8 @@
 		$unpackage$;
 
 		RAISE WARNING 'PostGIS Raster functionality have been unpackaged'
-		USING HINT = 'type `CREATE EXTENSION postgis_raster FROM unpackaged` to re-package'
-								 ' or source `uninstall_rtpostgis.sql` to drop.';
+		USING HINT = 'type `SELECT postgis_extensions_upgrade(); to repackage.'
+								 ' If you want to drop raster after, run: DROP EXTENSION postgis_raster;';
 	END IF;
 END
 $unpackage_if_needed$ LANGUAGE 'plpgsql';

Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in	2018-09-27 13:34:38 UTC (rev 16846)
+++ trunk/postgis/postgis.sql.in	2018-09-27 21:50:36 UTC (rev 16847)
@@ -2823,7 +2823,7 @@
 -- Changed: 3.0.0 also upgrade postgis_raster if it exists
 CREATE OR REPLACE FUNCTION postgis_extensions_upgrade() RETURNS text
 AS $$
-DECLARE rec record; sql text;
+DECLARE rec record; sql text; var_schema text;
 BEGIN
 	-- if at a version different from default version or we are at a dev version,
 	-- then do an upgrade to default version
@@ -2853,6 +2853,23 @@
 		sql = 'ALTER EXTENSION ' || rec.name || ' UPDATE TO ' || quote_ident(rec.default_version)   || ';';
 		EXECUTE sql;
 		RAISE NOTICE '%', sql;
+
+		-- If postgis raster functions still exist, but postgis_raster extension is not installed
+		-- then repackage as postgis_raster
+		IF rec.name = 'postgis' 
+			AND NOT EXISTS(SELECT 1 FROM pg_extension WHERE extname='postgis_raster') 
+			AND EXISTS(SELECT 1 FROM pg_proc WHERE proname LIKE 'raster%') THEN
+			SELECT n.nspname INTO var_schema 
+				FROM pg_catalog.pg_extension AS e 
+					INNER JOIN pg_catalog.pg_namespace AS n ON e.extnamespace = n.oid
+			WHERE e.extname = 'postgis';
+
+			sql = 'CREATE EXTENSION postgis_raster FROM unpackaged SCHEMA ' || quote_ident(var_schema) || ';';
+			EXECUTE sql;
+
+		END IF;
+
+
 	END LOOP;
 
 	RETURN @extschema at .postgis_full_version();



More information about the postgis-tickets mailing list