[postgis-tickets] [SCM] PostGIS branch master updated. 3.4.0rc1-89-ge1a3381fa

git at osgeo.org git at osgeo.org
Thu Aug 31 10:50:26 PDT 2023


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, master has been updated
       via  e1a3381fa706532b54108a762df6129d0aedce4e (commit)
       via  684daa95388dcb11fb553a3976210dd5f36958ab (commit)
       via  8db554622ce2c2c3c4d3b7c412cb3011b13b075c (commit)
      from  e9df66644c4a2d40b10f1946a32efba23c3041af (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 e1a3381fa706532b54108a762df6129d0aedce4e
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Aug 31 16:01:36 2023 +0200

    Try to drop all deprecated functions at the end of upgrade

diff --git a/.editorconfig b/.editorconfig
index 652bb84ad..03b109bda 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -82,3 +82,7 @@ indent_size = 4
 
 [*.xsl]
 indent_style = tab
+
+[postgis/common_after_upgrade.sql]
+indent_style = space
+indent_size = 4
diff --git a/postgis/common_after_upgrade.sql b/postgis/common_after_upgrade.sql
index fad82565f..45873e722 100644
--- a/postgis/common_after_upgrade.sql
+++ b/postgis/common_after_upgrade.sql
@@ -21,3 +21,80 @@
 -- DROP auxiliar function (created by common_before_upgrade.sql)
 DROP FUNCTION _postgis_drop_function_if_needed(text, text, text);
 
+
+-- Drop deprecated functions if possible
+DO LANGUAGE 'plpgsql'
+$POSTGIS_PROC_UPGRADE$
+DECLARE
+    new_name TEXT;
+    rec RECORD;
+    extrec RECORD;
+    sql TEXT;
+    detail TEXT;
+    hint TEXT;
+BEGIN
+
+    -- Try to drop all deprecated functions,
+    -- and report failure to do so as a WARNING
+    -- for the user to handle.
+    --
+    FOR rec IN
+
+        SELECT *, oid::regprocedure as proc
+        FROM pg_catalog.pg_proc
+        WHERE proname ~ 'deprecated_by_postgis'
+
+    LOOP --{
+
+        RAISE DEBUG 'Handling deprecated function %', rec.proc;
+
+        new_name := pg_catalog.regexp_replace(
+            rec.proc::text,
+            '_deprecated_by_postgis[^(]*\(.*',
+            ''
+        );
+
+        sql := pg_catalog.format('DROP FUNCTION %s', rec.proc);
+        --RAISE DEBUG 'SQL: %', sql;
+        BEGIN --{
+            EXECUTE sql;
+        EXCEPTION
+        WHEN OTHERS THEN -- }{
+            hint = 'Resolve the issue';
+            GET STACKED DIAGNOSTICS detail := PG_EXCEPTION_DETAIL;
+            IF detail LIKE '%view % depends%' THEN
+                hint = pg_catalog.format(
+                    'Replace the view changing all occurrences of %s in its definition with %s',
+                    rec.proc,
+                    new_name
+                );
+            END IF;
+            hint = hint || ' and upgrade again';
+
+            RAISE WARNING 'Deprecated function % left behind: %',
+                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_catalog.pg_extension e,
+                    pg_catalog.pg_depend d
+                WHERE
+                    d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
+                    d.refobjid = e.oid AND
+                    d.classid = 'pg_catalog.pg_proc'::pg_catalog.regclass AND
+                    d.objid = rec.proc::oid
+            LOOP
+                RAISE DEBUG 'Unpackaging % from extension %', rec.proc, extrec.extname;
+                sql := pg_catalog.format('ALTER EXTENSION %I DROP FUNCTION %s', extrec.extname, rec.proc);
+                EXECUTE sql;
+            END LOOP;
+
+        END; --}
+
+    END LOOP; --}
+END
+$POSTGIS_PROC_UPGRADE$;
diff --git a/utils/create_upgrade.pl b/utils/create_upgrade.pl
index eeaf4ed43..5de18a8a1 100755
--- a/utils/create_upgrade.pl
+++ b/utils/create_upgrade.pl
@@ -666,173 +666,6 @@ EOF
     $comment = '';
 }
 
-# If any deprecated function still exist, drop it now
-my $deprecated_names = '{' . ( join ',', @renamed_deprecated_functions) . '}';
-print <<"EOF";
--- Drop deprecated functions if possible
-DO LANGUAGE 'plpgsql'
-\$postgis_proc_upgrade\$
-DECLARE
-    deprecated_functions regprocedure[];
-    new_name TEXT;
-    rewrote_as_wrapper BOOLEAN;
-    rec RECORD;
-    extrec RECORD;
-    procrec RECORD;
-    sql TEXT;
-    detail TEXT;
-    hint TEXT;
-BEGIN
-    -- Fetch a list of deprecated functions
-
-    SELECT array_agg(oid::regprocedure)
-    FROM pg_catalog.pg_proc
-    WHERE proname = ANY ('${deprecated_names}'::name[])
-    INTO deprecated_functions;
-
-    RAISE DEBUG 'Handling deprecated functions: %', deprecated_functions;
-
---    -- Rewrite views using deprecated functions
---    -- to improve the odds of being able to drop them
---
---    FOR rec IN
---        SELECT n.nspname AS schemaname,
---            c.relname AS viewname,
---            pg_catalog.pg_get_userbyid(c.relowner) AS viewowner,
---            pg_catalog.pg_get_viewdef(c.oid) AS definition,
---            CASE
---                WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'WITH CASCADED CHECK OPTION'
---                WHEN 'check_option=local' = ANY (c.reloptions) THEN 'WITH LOCAL CHECK OPTION'
---                ELSE ''
---            END::text AS check_option
---        FROM pg_catalog.pg_class c
---        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
---        WHERE c.relkind = 'v'
---        AND pg_catalog.pg_get_viewdef(c.oid) ~ 'deprecated_by_postgis'
---    LOOP
---        sql := pg_catalog.format('CREATE OR REPLACE VIEW %I.%I AS %s %s',
---            rec.schemaname,
---            rec.viewname,
---            pg_catalog.regexp_replace(rec.definition, '_deprecated_by_postgis_[^(]*', '', 'g'),
---            rec.check_option
---        );
---        RAISE NOTICE 'Updating view % to not use deprecated signatures', rec.viewname;
---        BEGIN
---            EXECUTE sql;
---        EXCEPTION
---        WHEN OTHERS THEN
---                GET STACKED DIAGNOSTICS detail := PG_EXCEPTION_DETAIL;
---                RAISE WARNING 'Could not rewrite view % using deprecated functions', rec.viewname
---                        USING DETAIL = pg_catalog.format('%s: %s', SQLERRM, detail);
---        END;
---    END LOOP;
-
-    -- Try to drop all deprecated functions, or rewrite those
-    -- who cannot be drop and rewrite them in SQL
-
-    FOR rec IN SELECT pg_catalog.unnest(deprecated_functions) as proc
-    LOOP --{
-
-        RAISE DEBUG 'Handling deprecated function %', rec.proc;
-
-        new_name := pg_catalog.regexp_replace(
-            rec.proc::text,
-            '_deprecated_by_postgis[^(]*\\(.*',
-            ''
-        );
-
-        sql := pg_catalog.format('DROP FUNCTION %s', rec.proc);
-        --RAISE DEBUG 'SQL: %', sql;
-        BEGIN
-            EXECUTE sql;
-        EXCEPTION
-        WHEN OTHERS THEN
-            hint = 'Resolve the issue';
-            GET STACKED DIAGNOSTICS detail := PG_EXCEPTION_DETAIL;
-            IF detail LIKE '%view % depends%' THEN
-                hint = pg_catalog.format(
-                    'Replace the view changing all occurrences of %s in its definition with %s',
-                    rec.proc,
-                    new_name
-                );
-            END IF;
-            hint = hint || ' and upgrade again';
-
-            RAISE WARNING 'Deprecated function % left behind: %',
-                rec.proc, SQLERRM
-            USING DETAIL = detail, HINT = hint;
-
-            --
-            -- Try to rewrite the function as an SQL WRAPPER
-            -- {
-            SELECT pg_get_functiondef(oid) def, pronargs
-            FROM pg_catalog.pg_proc WHERE oid = rec.proc
-            INTO procrec;
-            --
-            -- TODO: don't even try if it's an aggregate or windowing
-            --       function (procrec.prokind)
-            -- TODO: don't even try if it's a scripting language function
-            --       function (procrec.prokind)
-            --
-            -- Force LANGUAGE to be SQL
-            sql := pg_catalog.regexp_replace(procrec.def, 'LANGUAGE [^ \n]*', 'LANGUAGE sql');
-            --RAISE DEBUG 'SQL (LANGUAGE): %', sql;
-            -- Change body to be a wrapper
-            sql := pg_catalog.regexp_replace(
-                sql,
-                -- Find a stricted match here ?
-                'AS .*',
-                pg_catalog.format(
-                    -- TODO: have the function raise a warning too ?
-                    'AS \$\$ SELECT %s(%s) \$\$',
-                    new_name,
-                    (
-                        SELECT array_to_string(
-                            array_agg('\$' || x),
-                            ','
-                        )
-                        FROM generate_series(1, procrec.pronargs) x
-                    )
-                )
-            );
-            RAISE DEBUG 'SQL: %', sql;
-            rewrote_as_wrapper := false;
-            BEGIN
-                EXECUTE sql;
-                rewrote_as_wrapper := true;
-            EXCEPTION
-            WHEN OTHERS THEN
-                RAISE WARNING
-                    'Deprecated function % could not be rewritten as a wrapper: % (%)',
-                    rec.proc, SQLERRM, SQLSTATE;
-            END;
-            --
-            --}
-
-
-            -- Drop the function from any extension it is part of
-            -- so dump/reloads still work
-            FOR extrec IN
-                SELECT e.extname
-                FROM
-                    pg_catalog.pg_extension e,
-                    pg_catalog.pg_depend d
-                WHERE
-                    d.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
-                    d.refobjid = e.oid AND
-                    d.classid = 'pg_catalog.pg_proc'::pg_catalog.regclass AND
-                    d.objid = rec.proc::oid
-            LOOP
-                RAISE DEBUG 'Unpackaging % from extension %', rec.proc, extrec.extname;
-                sql := pg_catalog.format('ALTER EXTENSION %I DROP FUNCTION %s', extrec.extname, rec.proc);
-                EXECUTE sql;
-            END LOOP;
-        END;
-    END LOOP; --}
-END
-\$postgis_proc_upgrade\$;
-EOF
-
 close(INPUT);
 
 print "DROP FUNCTION _postgis_upgrade_info();\n";

commit 684daa95388dcb11fb553a3976210dd5f36958ab
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Aug 31 13:13:14 2023 +0200

    Have _postgis_drop_function_if_needed rename rather than drop
    
    Renames functions to have suffix _deprecated_by_postgis_<version>
    Version becomes an optional parameter.
    
    References #5493

diff --git a/postgis/common_after_upgrade.sql b/postgis/common_after_upgrade.sql
index 87544acbd..fad82565f 100644
--- a/postgis/common_after_upgrade.sql
+++ b/postgis/common_after_upgrade.sql
@@ -19,5 +19,5 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
 -- DROP auxiliar function (created by common_before_upgrade.sql)
-DROP FUNCTION _postgis_drop_function_if_needed(text, text);
+DROP FUNCTION _postgis_drop_function_if_needed(text, text, text);
 
diff --git a/postgis/common_before_upgrade.sql b/postgis/common_before_upgrade.sql
index 878cc9545..210ca0ab9 100644
--- a/postgis/common_before_upgrade.sql
+++ b/postgis/common_before_upgrade.sql
@@ -34,11 +34,15 @@
 --         ORDER BY 1, 2, 3, 4;
 CREATE OR REPLACE FUNCTION _postgis_drop_function_if_needed(
 	function_name text,
-	function_arguments text) RETURNS void AS $$
+	function_arguments text,
+	deprecated_in_version text DEFAULT 'xxx'
+) RETURNS void AS $$
 DECLARE
-	sql_drop text;
+	sql text;
 	postgis_namespace OID;
-	matching_function REGPROCEDURE;
+	matching_function pg_catalog.pg_proc;
+	detail TEXT;
+	deprecated_suffix TEXT := '_deprecated_by_postgis_' || deprecated_in_version;
 BEGIN
 
 	-- Fetch install namespace for PostGIS
@@ -49,7 +53,7 @@ BEGIN
 	INTO postgis_namespace;
 
 	-- Find a function matching the given signature
-	SELECT oid
+	SELECT *
 	FROM pg_catalog.pg_proc p
 	WHERE pronamespace = postgis_namespace
 	AND pg_catalog.LOWER(p.proname) = pg_catalog.LOWER(function_name)
@@ -57,14 +61,20 @@ BEGIN
 	AND pg_catalog.LOWER(pg_catalog.pg_get_function_identity_arguments(p.oid)) ~ pg_catalog.LOWER(function_arguments)
 	INTO matching_function;
 
-	IF matching_function IS NOT NULL THEN
-		sql_drop := 'DROP FUNCTION ' || matching_function;
-		RAISE DEBUG 'SQL query: %', sql_drop;
+	IF matching_function.oid IS NOT NULL THEN
+		sql := format('ALTER FUNCTION %s RENAME TO %I',
+			matching_function.oid::regprocedure,
+			matching_function.proname || deprecated_suffix
+		);
+		RAISE WARNING 'SQL query: %', sql;
 		BEGIN
-			EXECUTE sql_drop;
+			EXECUTE sql;
 		EXCEPTION
 			WHEN OTHERS THEN
-				RAISE EXCEPTION 'Could not drop function %. You might need to drop dependant objects. Postgres error: %', function_name, SQLERRM;
+				GET STACKED DIAGNOSTICS detail := PG_EXCEPTION_DETAIL;
+				RAISE EXCEPTION 'Could not rename deprecated function %, got % (%)',
+					matching_function, SQLERRM, SQLSTATE
+				USING DETAIL = detail;
 		END;
 	END IF;
 

commit 8db554622ce2c2c3c4d3b7c412cb3011b13b075c
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Aug 31 09:52:41 2023 +0200

    Use a common before/after upgrade script for core and raster
    
    References #5493

diff --git a/extensions/postgis/Makefile.in b/extensions/postgis/Makefile.in
index 09ccc8c08..799fdf925 100644
--- a/extensions/postgis/Makefile.in
+++ b/extensions/postgis/Makefile.in
@@ -116,7 +116,8 @@ sql/spatial_ref_sys.sql: ../../spatial_ref_sys.sql | sql
 sql/spatial_ref_sys_config_dump.sql: ../../spatial_ref_sys.sql ../../utils/create_spatial_ref_sys_config_dump.pl | sql
 	$(PERL) @top_srcdir@/utils/create_spatial_ref_sys_config_dump.pl $< > $@
 
-sql/postgis_upgrade_for_extension.sql: ../../postgis/postgis_before_upgrade.sql sql/postgis_upgrade_for_extension.sql.in ../../postgis/postgis_after_upgrade.sql | sql
+#this keeps the @extschema at . in place since extension machinery will replace during install
+sql/postgis_upgrade_for_extension.sql: ../../postgis/common_before_upgrade.sql ../../postgis/postgis_before_upgrade.sql sql/postgis_upgrade_for_extension.sql.in ../../postgis/postgis_after_upgrade.sql ../../postgis/common_after_upgrade.sql | sql
 	#strip BEGIN/COMMIT since these are not allowed in extensions
 	# WARNING: we should make sure these are not internal to function bodies
 	cat $^ | $(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' > $@
diff --git a/extensions/postgis_raster/Makefile.in b/extensions/postgis_raster/Makefile.in
index ceb0eade2..4a2af9502 100644
--- a/extensions/postgis_raster/Makefile.in
+++ b/extensions/postgis_raster/Makefile.in
@@ -102,7 +102,7 @@ sql/rtpostgis_upgrade.sql: sql/rtpostgis_upgrade_for_extension.sql | sql
 	$(PERL) -pe "s/BEGIN\;//g ; s/COMMIT\;//g; s/^(DROP .*)\;/SELECT postgis_extension_drop_if_exists('$(EXTENSION)', '\1');\n\1\;/" $< > $@
 
 #this keeps the @extschema at . in place since extension machinery will replace during install
-sql/rtpostgis_upgrade_for_extension.sql: ../../raster/rt_pg/rtpostgis_upgrade_cleanup.sql sql/rtpostgis_upgrade_for_extension.sql.in ../../raster/rt_pg/rtpostgis_drop.sql | sql
+sql/rtpostgis_upgrade_for_extension.sql: ../../postgis/common_before_upgrade.sql ../../raster/rt_pg/rtpostgis_upgrade_cleanup.sql sql/rtpostgis_upgrade_for_extension.sql.in ../../raster/rt_pg/rtpostgis_drop.sql ../../postgis/common_after_upgrade.sql | sql
 	echo 'BEGIN;' > $@
 	cat $^ | sed -e 's/^BEGIN;$$//' -e 's/^COMMIT;$$//' >> $@
 	echo 'COMMIT;' >> $@
diff --git a/postgis/Makefile.in b/postgis/Makefile.in
index 095d1b300..0e972da7e 100644
--- a/postgis/Makefile.in
+++ b/postgis/Makefile.in
@@ -236,6 +236,10 @@ endif
 # Borrow the $libdir substitution from PGXS but customise by running the preprocessor
 # and adding the version number
 # replace @extschema at . with nothing, this is only used as placeholder for extension install
+#
+# TODO: create an intermediate product with @extschema@ in place, to reduce rules duplications
+#       in the extension/ folder
+#
 %.sql: %.sql.in
 	$(SQLPP) -I at top_srcdir@/libpgcommon -I at builddir@ $< > $@.tmp
 	grep -v '^#' $@.tmp | $(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g;s'@extschema@\.''g" > $@
@@ -246,7 +250,7 @@ postgis_upgrade.sql.in: postgis.sql ../utils/create_upgrade.pl
 	$(PERL) @top_srcdir@/utils/create_upgrade.pl $< > $@
 
 
-postgis_upgrade.sql: postgis_before_upgrade.sql postgis_upgrade.sql.in postgis_after_upgrade.sql
+postgis_upgrade.sql: common_before_upgrade.sql postgis_before_upgrade.sql postgis_upgrade.sql.in postgis_after_upgrade.sql common_after_upgrade.sql
 	echo "BEGIN;" > $@
 	cat $^ >> $@
 	echo "COMMIT;" >> $@
diff --git a/postgis/common_after_upgrade.sql b/postgis/common_after_upgrade.sql
new file mode 100644
index 000000000..87544acbd
--- /dev/null
+++ b/postgis/common_after_upgrade.sql
@@ -0,0 +1,23 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+--
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://postgis.net
+--
+-- Copyright (C) 2011-2020 Sandro Santilli <strk at kbt.io>
+-- Copyright (C) 2010-2012 Regina Obe <lr at pcorp.us>
+-- Copyright (C) 2009      Paul Ramsey <pramsey at cleverelephant.ca>
+--
+-- This is free software; you can redistribute and/or modify it under
+-- the terms of the GNU General Public Licence. See the COPYING file.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+-- This file will be appended at the very end of every
+-- sql upgrade script.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+-- DROP auxiliar function (created by common_before_upgrade.sql)
+DROP FUNCTION _postgis_drop_function_if_needed(text, text);
+
diff --git a/postgis/common_before_upgrade.sql b/postgis/common_before_upgrade.sql
new file mode 100644
index 000000000..878cc9545
--- /dev/null
+++ b/postgis/common_before_upgrade.sql
@@ -0,0 +1,72 @@
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+--
+-- PostGIS - Spatial Types for PostgreSQL
+-- http://postgis.net
+--
+-- Copyright (C) 2011-2012 Sandro Santilli <strk at kbt.io>
+-- Copyright (C) 2010-2013 Regina Obe <lr at pcorp.us>
+-- Copyright (C) 2009      Paul Ramsey <pramsey at cleverelephant.ca>
+--
+-- This is free software; you can redistribute and/or modify it under
+-- the terms of the GNU General Public Licence. See the COPYING file.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+-- This file contains utility functions for use by upgrade scripts
+-- Changes to this file affect *upgrade*.sql script.
+--
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+--
+-- Helper function to drop functions when they match the full signature
+-- Requires schema, name and __exact arguments__ as extracted from pg_catalog.pg_get_function_arguments
+-- You can extract the old function arguments using a query like:
+-- SELECT  p.oid as oid,
+--                 n.nspname as schema,
+--                 p.proname as name,
+--                 pg_catalog.pg_get_function_arguments(p.oid) as arguments
+--         FROM pg_catalog.pg_proc p
+--         LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
+--         WHERE
+--                 pg_catalog.LOWER(n.nspname) = pg_catalog.LOWER('public') AND
+--                 pg_catalog.LOWER(p.proname) = pg_catalog.LOWER('ST_AsGeoJson')
+--         ORDER BY 1, 2, 3, 4;
+CREATE OR REPLACE FUNCTION _postgis_drop_function_if_needed(
+	function_name text,
+	function_arguments text) RETURNS void AS $$
+DECLARE
+	sql_drop text;
+	postgis_namespace OID;
+	matching_function REGPROCEDURE;
+BEGIN
+
+	-- Fetch install namespace for PostGIS
+	SELECT n.oid
+	FROM pg_catalog.pg_proc p
+	JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
+	WHERE proname = 'postgis_full_version'
+	INTO postgis_namespace;
+
+	-- Find a function matching the given signature
+	SELECT oid
+	FROM pg_catalog.pg_proc p
+	WHERE pronamespace = postgis_namespace
+	AND pg_catalog.LOWER(p.proname) = pg_catalog.LOWER(function_name)
+	AND pg_catalog.pg_function_is_visible(p.oid)
+	AND pg_catalog.LOWER(pg_catalog.pg_get_function_identity_arguments(p.oid)) ~ pg_catalog.LOWER(function_arguments)
+	INTO matching_function;
+
+	IF matching_function IS NOT NULL THEN
+		sql_drop := 'DROP FUNCTION ' || matching_function;
+		RAISE DEBUG 'SQL query: %', sql_drop;
+		BEGIN
+			EXECUTE sql_drop;
+		EXCEPTION
+			WHEN OTHERS THEN
+				RAISE EXCEPTION 'Could not drop function %. You might need to drop dependant objects. Postgres error: %', function_name, SQLERRM;
+		END;
+	END IF;
+
+END;
+$$ LANGUAGE plpgsql;
diff --git a/postgis/postgis_before_upgrade.sql b/postgis/postgis_before_upgrade.sql
index da945fc44..f8607f216 100644
--- a/postgis/postgis_before_upgrade.sql
+++ b/postgis/postgis_before_upgrade.sql
@@ -20,59 +20,6 @@
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
 
--- Helper function to drop functions when they match the full signature
--- Requires schema, name and __exact arguments__ as extracted from pg_catalog.pg_get_function_arguments
--- You can extract the old function arguments using a query like:
--- SELECT  p.oid as oid,
---                 n.nspname as schema,
---                 p.proname as name,
---                 pg_catalog.pg_get_function_arguments(p.oid) as arguments
---         FROM pg_catalog.pg_proc p
---         LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
---         WHERE
---                 pg_catalog.LOWER(n.nspname) = pg_catalog.LOWER('public') AND
---                 pg_catalog.LOWER(p.proname) = pg_catalog.LOWER('ST_AsGeoJson')
---         ORDER BY 1, 2, 3, 4;
-CREATE OR REPLACE FUNCTION _postgis_drop_function_if_needed(
-	function_name text,
-	function_arguments text) RETURNS void AS $$
-DECLARE
-	sql_drop text;
-	postgis_namespace OID;
-	matching_function REGPROCEDURE;
-BEGIN
-
-	-- Fetch install namespace for PostGIS
-	SELECT n.oid
-	FROM pg_catalog.pg_proc p
-	JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
-	WHERE proname = 'postgis_full_version'
-	INTO postgis_namespace;
-
-	-- Find a function matching the given signature
-	SELECT oid
-	FROM pg_catalog.pg_proc p
-	WHERE pronamespace = postgis_namespace
-	AND pg_catalog.LOWER(p.proname) = pg_catalog.LOWER(function_name)
-	AND pg_catalog.pg_function_is_visible(p.oid)
-	AND pg_catalog.LOWER(pg_catalog.pg_get_function_identity_arguments(p.oid)) ~ pg_catalog.LOWER(function_arguments)
-	INTO matching_function;
-
-	IF matching_function IS NOT NULL THEN
-		sql_drop := 'DROP FUNCTION ' || matching_function;
-		RAISE DEBUG 'SQL query: %', sql_drop;
-		BEGIN
-			EXECUTE sql_drop;
-		EXCEPTION
-			WHEN OTHERS THEN
-				RAISE EXCEPTION 'Could not drop function %. You might need to drop dependant objects. Postgres error: %', function_name, SQLERRM;
-		END;
-	END IF;
-
-END;
-$$ LANGUAGE plpgsql;
-
-
 -- FUNCTION AddGeometryColumn signature dropped
 -- (catalog_name character varying, schema_name character varying, table_name character varying, column_name character varying, new_srid integer, new_type character varying, new_dim integer, use_typmod boolean)
 SELECT _postgis_drop_function_if_needed
@@ -235,7 +182,3 @@ BEGIN
 END;
 $$;
 
-
--- DROP auxiliar function (created above)
-DROP FUNCTION _postgis_drop_function_if_needed(text, text);
-
diff --git a/raster/rt_pg/Makefile.in b/raster/rt_pg/Makefile.in
index 4fa8a748c..7b0627fe9 100644
--- a/raster/rt_pg/Makefile.in
+++ b/raster/rt_pg/Makefile.in
@@ -124,6 +124,10 @@ endif
 # Borrow the $libdir substitution from PGXS but customise by running the preprocessor
 # and adding the version number
 # replace @extschema at . with nothing, this is only used as placeholder for extension install
+#
+# TODO: create an intermediate product with @extschema@ in place, to reduce rules duplications
+#       in the extension/ folder
+#
 %.sql: %.sql.in
 	$(SQLPP) -I at top_builddir@/postgis/ $< > $@.tmp
 	grep -v '^#' $@.tmp | \
@@ -151,7 +155,7 @@ $(SQL_OBJS): ../../postgis/sqldefines.h ../../postgis_revision.h
 rtpostgis_upgrade.sql.in: rtpostgis.sql ../../utils/create_upgrade.pl
 	$(PERL) @top_srcdir@/utils/create_upgrade.pl $< > $@
 
-rtpostgis_upgrade.sql: rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rtpostgis_drop.sql
+rtpostgis_upgrade.sql: ../../postgis/common_before_upgrade.sql rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rtpostgis_drop.sql ../../postgis/common_after_upgrade.sql
 	echo 'BEGIN;' > $@
 	cat $^ | sed -e 's/^BEGIN;$$//' -e 's/^COMMIT;$$//' >> $@
 	echo 'COMMIT;' >> $@

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

Summary of changes:
 .editorconfig                         |   4 +
 extensions/postgis/Makefile.in        |   3 +-
 extensions/postgis_raster/Makefile.in |   2 +-
 postgis/Makefile.in                   |   6 +-
 postgis/common_after_upgrade.sql      | 100 ++++++++++++++++++++
 postgis/common_before_upgrade.sql     |  82 +++++++++++++++++
 postgis/postgis_before_upgrade.sql    |  57 ------------
 raster/rt_pg/Makefile.in              |   6 +-
 utils/create_upgrade.pl               | 167 ----------------------------------
 9 files changed, 199 insertions(+), 228 deletions(-)
 create mode 100644 postgis/common_after_upgrade.sql
 create mode 100644 postgis/common_before_upgrade.sql


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list