[postgis-tickets] [SCM] PostGIS branch stable-3.1 updated. 3.1.6-8-g07f6b5f13

git at osgeo.org git at osgeo.org
Fri Aug 5 23:36:03 PDT 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.1 has been updated
       via  07f6b5f1371f72ff5b04871162882459968f89d7 (commit)
      from  8ae2e1c1d82a10c581493e3154db81df019e17f1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 07f6b5f1371f72ff5b04871162882459968f89d7
Author: Sandro Santilli <strk at kbt.io>
Date:   Sat Aug 6 07:07:48 2022 +0200

    Guard against downgrades
    
    References #5202 in 3.1 branch (3.1.7dev)

diff --git a/NEWS b/NEWS
index e9c7559c1..f73a249d1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-PostGIS 3.1.7
+PostGIS 3.1.7dev
 2022/xx/xx
 
 * Bug Fixes
@@ -6,6 +6,7 @@ PostGIS 3.1.7
   - #5139, PostGIS causes to_jsonb to no longer be parallel safe,
            ST_AsGeoJSON and ST_AsGML are also parallel unsafe
            (Regina Obe, Paul Ramsey)
+  - #5202, Guard against downgrades (Sandro Santilli)
 
 PostGIS 3.1.6
 2022/07/20
diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl
index 7e5ee93b7..611e8194e 100755
--- a/utils/postgis_proc_upgrade.pl
+++ b/utils/postgis_proc_upgrade.pl
@@ -91,6 +91,7 @@ my $sql_file = $ARGV[0];
 my $module = 'postgis';
 my $soname = '';
 my $version_to = "";
+my $version_to_full = "";
 my $version_to_num = 0;
 my $version_from = $ARGV[1];
 my $version_from_num = 0;
@@ -132,8 +133,9 @@ close(INPUT);
 die "Unable to locate target new version number in $sql_file\n"
   if( !$version_to );
 
-if ( $version_to =~ /(\d+)\.(\d+)\..*/ )
+if ( $version_to =~ /(\d+)\.(\d+)\.(\d+)([^' ]*)/ )
 {
+    $version_to_full = $1 . '.' . $2 . '.' . $3 . $4;
     $version_to = $1 . "." . $2;
     $version_to_num = 100 * $1 + $2;
 }
@@ -144,7 +146,7 @@ else
 
 print qq{
 --
--- UPGRADE SCRIPT TO PostGIS $version_to
+-- UPGRADE SCRIPT TO PostGIS $version_to_full
 --
 
 };
@@ -160,7 +162,7 @@ print "SET search_path TO $schema;\n" if $schema;
 #
 while(<DATA>)
 {
-    s/NEWVERSION/$version_to/g;
+    s/NEWVERSION/$version_to_full/g;
     s/MODULE/$module/g;
     print;
 }
@@ -695,6 +697,8 @@ DO $$
 DECLARE
     old_scripts text;
     new_scripts text;
+    old_ver_int int[];
+    new_ver_int int[];
     old_maj text;
     new_maj text;
 BEGIN
@@ -717,8 +721,43 @@ BEGIN
         SELECT into old_scripts MODULE_scripts_installed();
     END;
     SELECT into new_scripts 'NEWVERSION';
-    SELECT into old_maj pg_catalog.substring(old_scripts, 1, 1);
-    SELECT into new_maj pg_catalog.substring(new_scripts, 1, 1);
+
+    BEGIN
+        new_ver_int := pg_catalog.string_to_array(
+            pg_catalog.regexp_replace(
+                new_scripts,
+                '[^\d.].*',
+                ''
+            ),
+            '.'
+        )::int[];
+    EXCEPTION WHEN OTHERS THEN
+        RAISE EXCEPTION 'Cannot parse new version % into integers', new_scripts;
+    END;
+
+    BEGIN
+        old_ver_int := pg_catalog.string_to_array(
+            pg_catalog.regexp_replace(
+                old_scripts,
+                '[^\d.].*',
+                ''
+            ),
+            '.'
+        )::int[];
+    EXCEPTION WHEN OTHERS THEN
+        RAISE EXCEPTION 'Cannot parse old version % into integers', old_scripts;
+    END;
+
+    -- Guard against downgrade
+    IF new_ver_int < old_ver_int
+    THEN
+        RAISE EXCEPTION 'Downgrade of MODULE from version % to version % is forbidden', old_scripts, new_scripts;
+    END IF;
+
+
+    -- Check for hard-upgrade being required
+    SELECT into old_maj pg_catalog.substring(old_scripts,1, 1);
+    SELECT into new_maj pg_catalog.substring(new_scripts,1, 1);
 
     -- 2.x to 3.x was upgrade-compatible, see
     -- https://trac.osgeo.org/postgis/ticket/4170#comment:1

-----------------------------------------------------------------------

Summary of changes:
 NEWS                          |  3 ++-
 utils/postgis_proc_upgrade.pl | 49 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 46 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list