[postgis-tickets] r16713 - Consider 3.x upgrade-compatible with 2.x

Sandro Santilli strk at kbt.io
Wed Sep 5 09:24:34 PDT 2018


Author: strk
Date: 2018-09-05 09:24:34 -0700 (Wed, 05 Sep 2018)
New Revision: 16713

Modified:
   trunk/utils/postgis_proc_upgrade.pl
Log:
Consider 3.x upgrade-compatible with 2.x

Closes #4170

As I was at it, I also replaced the use of a temporary function
with a DO block.

Modified: trunk/utils/postgis_proc_upgrade.pl
===================================================================
--- trunk/utils/postgis_proc_upgrade.pl	2018-09-02 19:03:05 UTC (rev 16712)
+++ trunk/utils/postgis_proc_upgrade.pl	2018-09-05 16:24:34 UTC (rev 16713)
@@ -467,9 +467,7 @@
 
 __END__
 
-CREATE OR REPLACE FUNCTION postgis_major_version_check()
-RETURNS text
-AS '
+DO $$
 DECLARE
 	old_scripts text;
 	new_scripts text;
@@ -491,26 +489,26 @@
 	BEGIN
 		SELECT into old_scripts MODULE_lib_version();
 	EXCEPTION WHEN OTHERS THEN
-		RAISE DEBUG ''Got %'', SQLERRM;
+		RAISE DEBUG 'Got %', SQLERRM;
 		SELECT into old_scripts MODULE_scripts_installed();
 	END;
-	SELECT into new_scripts ''NEWVERSION'';
+	SELECT into new_scripts 'NEWVERSION';
 	SELECT into old_maj substring(old_scripts from 1 for 2);
 	SELECT into new_maj substring(new_scripts from 1 for 2);
 
+	-- 2.x to 3.x was upgrade-compatible, see
+	-- https://trac.osgeo.org/postgis/ticket/4170#comment:1
+	IF new_maj = '3' AND old_maj = '2' THEN
+		old_maj = '3'; -- let's pretend old major = new major
+	END IF;
+
 	IF old_maj != new_maj THEN
-		RAISE EXCEPTION ''Upgrade of MODULE from version % to version % requires a dump/reload. See PostGIS manual for instructions'', old_scripts, new_scripts;
-	ELSE
-		RETURN ''Scripts versions checked for upgrade: ok'';
+		RAISE EXCEPTION 'Upgrade of MODULE from version % to version % requires a dump/reload. See PostGIS manual for instructions', old_scripts, new_scripts;
 	END IF;
 END
-'
+$$
 LANGUAGE 'plpgsql';
 
-SELECT postgis_major_version_check();
-
-DROP FUNCTION postgis_major_version_check();
-
 CREATE TEMPORARY TABLE _postgis_upgrade_info AS WITH versions AS (
   SELECT 'NEWVERSION'::text as upgraded,
   MODULE_scripts_installed() as installed



More information about the postgis-tickets mailing list