[postgis-tickets] [SCM] PostGIS branch main updated. 3.2.0-10-g832131a8e

git at osgeo.org git at osgeo.org
Wed Dec 22 11:21:11 PST 2021


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, main has been updated
       via  832131a8eb00cbfc14dd2887f3bea1c09a9e0011 (commit)
      from  43f92d9a8f90eb3541a5d22296a74d136ab59fd4 (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 832131a8eb00cbfc14dd2887f3bea1c09a9e0011
Author: Sandro Santilli <strk at kbt.io>
Date:   Wed Dec 22 20:15:24 2021 +0100

    Rewrite deprecated function in SQL, to avoid referencing old libraries
    
    References #5033 in master/main branch (3.3.0dev)
    
    NOTE: still drop the function from CI after upgrade because otherwise
          they will depend on PostGIS types (for arguments) and thus prevent
          dropping postgis extension

diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl
index 5071c0f0e..62c28022e 100755
--- a/utils/postgis_proc_upgrade.pl
+++ b/utils/postgis_proc_upgrade.pl
@@ -239,24 +239,6 @@ BEGIN
     -- Rename old function, to avoid ambiguities and eventually drop
     ALTER FUNCTION $name( $args ) RENAME TO ${renamed};
 
-    -- Drop the function from any extension it is part of
-    -- so dump/reloads still work
-    FOR rec IN
-        SELECT e.extname
-        FROM
-            pg_extension e,
-            pg_depend d
-        WHERE
-            d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
-            d.refobjid = e.oid AND
-            d.classid = 'pg_proc'::regclass AND
-            d.objid = replaced_proc::oid
-    LOOP
-        RAISE DEBUG 'Unpackaging ${renamed} from extension %', rec.extname;
-        sql := format('ALTER EXTENSION %I DROP FUNCTION ${renamed}(${args})', rec.extname);
-        EXECUTE sql;
-    END LOOP;
-
 
 END;
 \$postgis_proc_upgrade\$;
@@ -605,6 +587,8 @@ DO LANGUAGE 'plpgsql'
 DECLARE
     deprecated_functions regprocedure[];
     rec RECORD;
+    extrec RECORD;
+    procrec RECORD;
     sql TEXT;
     detail TEXT;
     hint TEXT;
@@ -651,12 +635,49 @@ BEGIN
 --        END;
 --    END LOOP;
 
-    -- Try to drop all deprecated functions, raising a warning
-    -- for each one which cannot be drop
+    -- Try to drop all deprecated functions, or rewrite those
+    -- who cannot be drop and rewrite them in SQL
 
     FOR rec IN SELECT unnest(deprecated_functions) as proc
     LOOP --{
 
+        -- Rewrite the function as an SQL WRAPPER
+
+        SELECT pg_get_functiondef(oid) def, pronargs
+        FROM pg_proc WHERE oid = rec.proc
+        INTO procrec;
+
+        -- Force LANGUAGE to be SQL
+        sql := regexp_replace(procrec.def, 'LANGUAGE [^ \n]*', 'LANGUAGE sql');
+
+        --RAISE DEBUG 'SQL (LANGUAGE): %', sql;
+
+        -- Change body to be a wrapper
+        sql := regexp_replace(
+            sql,
+			-- Find a stricted match here ?
+            'AS .*',
+            format(
+                -- TODO: have the function raise a warning too ?
+                'AS \$\$ SELECT %s(%s) \$\$',
+                regexp_replace(
+                    rec.proc::text,
+                    '_deprecated_by_postgis[^(]*\\(.*',
+                    ''
+                ),
+                (
+                    SELECT array_to_string(
+                        array_agg('\$' || x),
+                        ','
+                    )
+                    FROM generate_series(1, procrec.pronargs) x
+                )
+            )
+        );
+
+        RAISE DEBUG 'SQL: %', sql;
+        EXECUTE sql;
+
         sql := format('DROP FUNCTION %s', rec.proc);
         --RAISE DEBUG 'SQL: %', sql;
         BEGIN
@@ -673,8 +694,26 @@ BEGIN
                 );
             END IF;
             hint = hint || ' and upgrade again';
-            RAISE WARNING 'Deprecated function % left behind: %', rec.proc, SQLERRM
+            RAISE WARNING 'Deprecated function % left behind as a wrapper: %', rec.proc, SQLERRM
             USING DETAIL = detail, HINT = hint;
+
+            -- Drop the function from any extension it is part of
+            -- so dump/reloads still work
+            FOR extrec IN
+                SELECT e.extname
+                FROM
+                    pg_extension e,
+                    pg_depend d
+                WHERE
+                    d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
+                    d.refobjid = e.oid AND
+                    d.classid = 'pg_proc'::regclass AND
+                    d.objid = rec.proc::oid
+            LOOP
+                RAISE DEBUG 'Unpackaging % from extension %', rec.proc, extrec.extname;
+                sql := format('ALTER EXTENSION %I DROP FUNCTION %s', extrec.extname, rec.proc);
+                EXECUTE sql;
+            END LOOP;
         END;
     END LOOP; --}
 END

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

Summary of changes:
 utils/postgis_proc_upgrade.pl | 81 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 60 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list