[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0rc2-99-g984383dc7

git at osgeo.org git at osgeo.org
Fri Sep 16 11:00:57 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, master has been updated
       via  984383dc79ffdc185356a37db9b6bc283f7b4c2c (commit)
      from  15b471af52705e753ad8461dcbe6f0192f7d4e7f (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 984383dc79ffdc185356a37db9b6bc283f7b4c2c
Author: Sandro Santilli <strk at kbt.io>
Date:   Sat Jul 30 07:26:42 2022 +0200

    Refactor extension upgrade mechanism
    
    Install <version>--ANY upgrade paths
    
    These <extension>--<version>--ANY.sql upgrade files will be symlinks
    ( or copies, on systems not supporting symlinks ) to an empty upgrade
    template file named <extension>--TEMPLATED--TO--ANY.sql and be
    overwritten by any future versions of PostGIS, keeping the overall
    number of upgrade paths down ( see #5092 )
    
    Presence of these upgrade paths will allow ALTER EXTENSION going
    from any version to any other version by stepping by the fake "ANY"
    version. This allows us to stop updating pg_extension table,
    fixing #5194 in a more generic way.
    
    Stop installing the "<version>--<version>next" and
    "<version>next--<version>" as the same thing can be done by stepping
    by the "ANY" version. Update run_test.pl script accordingly to use
    ANY instead of "next" for self-upgrading newer PostGIS
    
    Add support for installing missing upgrade paths in the `postgis`
    commandline, to allow upgrading from newly-released stable branches
    to previously-released feature branches.
    
    Include NEWS entries

diff --git a/NEWS b/NEWS
index 64455f774..aeb9351d5 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,13 @@ xxxx/xx/xx
   - #5231, PG15 no longer compiles against PostGIS 3.2 - 3.4
     because SQL/JSON removed upstream (Regina Obe)
 
+* New Features *
+  - New install-extension-upgrades command in postgis script (Sandro Santilli)
+
+ * Enhancements *
+  - #5194, do not update system catalogs from postgis_extensions_upgrade (Sandro Santilli)
+  - #5092, reduce number of upgrade paths installed on system (Sandro Santilli)
+
 PostGIS 3.3.0
 2022/08/26
 
diff --git a/extensions/address_standardizer/Makefile.in b/extensions/address_standardizer/Makefile.in
index 9c12a4e4d..20bd88ff5 100644
--- a/extensions/address_standardizer/Makefile.in
+++ b/extensions/address_standardizer/Makefile.in
@@ -209,6 +209,11 @@ abs_topbuilddir=$(abspath $(top_builddir))
 
 VPATH = $(srcdir)
 
+INSTALLED_UPGRADE_SCRIPTS +=  \
+	$(wildcard $(EXTDIR)/$(EXTENSION)_data_us--*--$(EXTVERSION).sql) \
+	$(wildcard $(EXTDIR)/$(EXTENSION)_data_us--*--ANY.sql) \
+	$(NULL)
+
 install: all installdirs
 	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
 ifdef DOCS
diff --git a/extensions/upgrade-paths-rules.mk b/extensions/upgrade-paths-rules.mk
index 27dff04bb..9dbf9a484 100644
--- a/extensions/upgrade-paths-rules.mk
+++ b/extensions/upgrade-paths-rules.mk
@@ -1,23 +1,40 @@
 EXTDIR=$(DESTDIR)$(datadir)/$(datamoduledir)
 
+TAG_UPGRADE=$(EXTENSION)--TEMPLATED--TO--ANY.sql
+
 install: install-upgrade-paths
 
 # The "next" lines are a cludge to allow upgrading between different
 # revisions of the same version
-install-upgrade-paths:
+#
+# TODO: drop the "next" lines, give users instruction to use:
+#
+#   SELECT postgis_extensions_upgrade();
+#
+# Or:
+#
+#   ALTER EXTENSION postgis UPDATE TO 'ANY';
+#   ALTER EXTENSION postgis UPDATE;
+#
+install-upgrade-paths: tag-as-any
 	tpl='$(EXTENSION)--ANY--$(EXTVERSION).sql'; \
 	$(INSTALL_DATA) sql/$${tpl} "$(EXTDIR)/$${tpl}"; \
-	ln -fs "$${tpl}" $(EXTDIR)/$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql; \
-	ln -fs "$${tpl}" $(EXTDIR)/$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql; \
-	for OLD_VERSION in $(UPGRADEABLE_VERSIONS); do \
-		ln -fs "$${tpl}" $(EXTDIR)/$(EXTENSION)--$$OLD_VERSION--$(EXTVERSION).sql; \
-	done
+	$(INSTALL_DATA) "sql/$(TAG_UPGRADE)" "$(EXTDIR)/$(TAG_UPGRADE)"; \
+	ln -fs "$(TAG_UPGRADE)" $(EXTDIR)/$(EXTENSION)--$(EXTVERSION)--ANY.sql; \
+	$(abs_topbuilddir)/loader/postgis install-extension-upgrades $(UPGRADEABLE_VERSIONS)
+
+tag-as-any: sql/$(TAG_UPGRADE)
+
+sql/$(TAG_UPGRADE): $(MAKEFILE_LIST) | sql
+	echo '-- Just tag extension $(EXTENSION) version as "ANY"' > $@
+	echo '-- Installed by $(EXTENSION) $(EXTVERSION)' >> $@
+	echo '-- Built on $(shell date)' >> $@
 
 uninstall: uninstall-upgrade-paths
 
 INSTALLED_UPGRADE_SCRIPTS = \
-	$(wildcard $(EXTDIR)/*$(EXTVERSION).sql) \
-	$(wildcard $(EXTDIR)/*$(EXTVERSION)next.sql) \
+	$(wildcard $(EXTDIR)/$(EXTENSION)--*--$(EXTVERSION).sql) \
+	$(wildcard $(EXTDIR)/$(EXTENSION)--*--ANY.sql) \
 	$(NULL)
 
 uninstall-upgrade-paths:
diff --git a/loader/postgis.pl b/loader/postgis.pl
index 22794ac67..c4ec9eb75 100644
--- a/loader/postgis.pl
+++ b/loader/postgis.pl
@@ -4,12 +4,14 @@
 # PostGIS - Spatial Types for PostgreSQL
 # http://postgis.net
 #
-# Copyright (C) 2020 Sandro Santilli <strk at kbt.io>
+# Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
 #
 # This is free software; you can redistribute and/or modify it under
 # the terms of the GNU General Public Licence. See the COPYING file.
 #
 
+use File::Basename;
+
 
 sub usage
 {
@@ -19,10 +21,135 @@ Commands:
   enable <database>  enable PostGIS in given database
   upgrade <database> upgrade PostGIS in given database
   status <database>  print PostGIS status in given database
+  install-extension-upgrades [--pg_sharedir <dir>] [<from>...]
+		Ensure files required to upgrade PostGIS from
+		the given version are installed on the system.
+		The <from> arguments may be either version numbers
+		or PostgreSQL share directories to scan to find available
+		ones.
 };
 
 }
 
+sub install_upgrade_from
+{
+	my ( $SHAREDIR, $from ) = @_;
+
+	#print "SHAREDIR: $SHAREDIR\n";
+	#print "FROM: $from\n";
+	die "Please specify a sharedir and a version to install upgrade support for.\n"
+		unless $from;
+
+	my %supported_extension = (
+		'postgis' => 1,
+		'postgis_raster' => 1,
+		'postgis_sfcgal' => 1,
+		'postgis_tiger_geocoder' => 1,
+		'postgis_topology' => 1
+	);
+
+	# sanify ${from}
+	die "'${from}': invalid version, only 3 dot-separated numbers optionally followed by alphanumeric string are allowed\n"
+		unless $from =~ /^[0-9]*\.[0-9]*\.[0-9]*[a-z1-9]*/;
+
+	# Reserver versions
+
+	my $EXTDIR = ${SHAREDIR} . '/extension';
+
+	#for ls postgis*.control
+	while (my $cfile = glob("${EXTDIR}/postgis*.control")) {
+		# Do stuff
+		#print " CFILE: ${cfile}\n";
+		my $extname = basename($cfile, '.control');
+
+		unless ( exists( $supported_extension{$extname} ) )
+		{
+			print STDERR "NOTICE: extension [${extname}] is not a core PostGIS extension\n";
+			next;
+		}
+
+		#print " EXTENSION: [${extname}]\n";
+
+		# TODO: if the target is before 3.3.0 we need to symlink
+		#       ${extname}--ANY--${to} to ${extname}--${from}--${to}
+
+		my $shcmd = "ln -fvs '${extname}--TEMPLATED--TO--ANY.sql' '${EXTDIR}/${extname}--${from}--ANY.sql'";
+		#print " CMD: ${shcmd}\n";
+		my $rv = system($shcmd);
+		if ( $rv ) {
+			die "Error encountered running: $cmd: $!";
+		}
+
+	}
+
+	return 0; # success
+}
+
+sub install_upgrade_from_available
+{
+	my ($SHAREDIR) = @_;
+	my $EXTDIR = ${SHAREDIR} . '/extension';
+
+	#print "EXTDIR: ${EXTDIR}\n";
+
+	opendir(my $d, $EXTDIR) || die "Cannot read ${EXTDIR} directory\n";
+	my @files = grep { /^postgis--/ && ! /--.*--/ } readdir($d);
+	foreach ( @files )
+	{
+		m/^postgis--(.*)\.sql/;
+		my $ver = $1;
+		next if $ver eq 'unpackaged'; # we don't want to install upgrade from unpackaged
+		print "Found version $ver\n";
+		return $rv if my $rv = install_upgrade_from $SHAREDIR, $ver;
+		#return $rv if $rv; # first failure aborts all
+	}
+	closedir($d);
+
+	exit 0; # success
+}
+
+sub install_extension_upgrades
+{
+	my $DEFSHAREDIR = `pg_config --sharedir`;
+	chop($DEFSHAREDIR);
+	my $SHAREDIR = ${DEFSHAREDIR};
+
+	my @ver;
+
+	for ( my $i=0; $i<@_; $i++ )
+	{
+		if ( $_[$i] eq '--pg_sharedir' )
+		{
+			$i++ < @_ - 1 || die '--pg_sharedir requires an argument';
+			$SHAREDIR = $_[$i];
+			die "$SHAREDIR is not a directory" unless -d ${SHAREDIR};
+			next;
+		}
+
+		push @ver, $_[$i];
+	}
+
+	print "Installation target: ${SHAREDIR}\n";
+
+	if ( 0 == @ver )
+	{
+		print "No versions given, will scan ${SHAREDIR}\n";
+		push @ver, ${SHAREDIR};
+	}
+
+
+	foreach ( @ver )
+	{
+		my $v = $_;
+		if ( -d $v ) {
+			install_upgrade_from_available($SHAREDIR, $v);
+		} else {
+			install_upgrade_from($SHAREDIR, $v);
+		}
+	}
+
+}
+
 
 sub enable
 {
@@ -126,6 +253,9 @@ elsif ( $cmd eq "upgrade" ) {
 elsif ( $cmd eq "status" ) {
 	exit status(@ARGV);
 }
+elsif ( $cmd eq "install-extension-upgrades" ) {
+	exit install_extension_upgrades(@ARGV);
+}
 else {
 	print STDERR "Unrecognized command: $cmd\n";
   usage(STDERR);
diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in
index 62192b317..798e26eea 100644
--- a/postgis/postgis.sql.in
+++ b/postgis/postgis.sql.in
@@ -3024,7 +3024,7 @@ BEGIN
 							SELECT 1 FROM pg_catalog.pg_class c
 							JOIN pg_catalog.pg_namespace n ON (c.relnamespace = n.oid )
 							WHERE n.nspname = 'tiger' AND c.relname = 'geocode_settings') )
-			THEN --}{
+			THEN --}{ -- the code is unpackaged
 				-- Force install in same schema as postgis
 				SELECT INTO var_schema n.nspname
 				  FROM pg_namespace n, pg_proc p
@@ -3048,36 +3048,16 @@ BEGIN
 				EXECUTE sql;
 			ELSE
 				RAISE DEBUG 'Skipping % (not in use)', rec.name;
-			END IF;
-		ELSE -- IF target_version != rec.installed_version THEN --}{
-			sql = '';
-			-- If logged in as super user
-			-- force an update regardless if at target version, no downgrade allowed
-			IF (SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER)
-						AND pg_catalog.substring(target_version, '[0-9]+\.[0-9]+\.[0-9]+')
-								>= pg_catalog.substring(rec.installed_version, '[0-9]+\.[0-9]+\.[0-9]+') THEN
-					sql = format(
-						'UPDATE pg_catalog.pg_extension SET extversion = ''ANY'' WHERE extname = %1$L;'
-						'ALTER EXTENSION %1$I UPDATE TO %2$I',
-						rec.name, target_version
-				);
-			-- sandboxed users do standard upgrade
-			ELSIF pg_catalog.substring(target_version, '[0-9]+\.[0-9]+\.[0-9]+')
-								>= pg_catalog.substring(rec.installed_version, '[0-9]+\.[0-9]+\.[0-9]+') THEN
-				sql = format(
+			END IF; --}
+		ELSE -- The code is already packaged, upgrade it --}{
+			sql = format(
+				'ALTER EXTENSION %1$I UPDATE TO ANY;',
 				'ALTER EXTENSION %1$I UPDATE TO %2$I',
 				rec.name, target_version
 				);
-			END IF;
-			IF sql > '' THEN
-				RAISE NOTICE 'Updating extension % %',
-					rec.name, rec.installed_version;
-				RAISE DEBUG '%', sql;
-				EXECUTE sql;
-			ELSE
-				RAISE NOTICE 'Downgrade % from % to % not allowed',
-						rec.name, rec.installed_version, target_version;
-			END IF;
+			RAISE NOTICE 'Updating extension % %', rec.name, rec.installed_version;
+			RAISE DEBUG '%', sql;
+			EXECUTE sql;
 		END IF; --}
 
 	END LOOP; --}
diff --git a/regress/run_test.pl b/regress/run_test.pl
index e31f7556d..11d144952 100755
--- a/regress/run_test.pl
+++ b/regress/run_test.pl
@@ -1565,6 +1565,23 @@ sub prepare_spatial
 	return 1;
 }
 
+sub upgrade_extension_sql
+{
+    my ($extname, $from, $to) = @_;
+
+    my $sql = '';
+    if ( "${libver}" eq "${to}" ) {
+        if ( semver_lessthan($to, "3.3.0") ) {
+            $sql .= "ALTER EXTENSION $extname UPDATE TO '${to}next'; ";
+        } else {
+            $sql .= "ALTER EXTENSION $extname UPDATE TO 'ANY'; ";
+        }
+    }
+    $sql .= "ALTER EXTENSION $extname UPDATE TO '${to}'";
+
+    return $sql;
+}
+
 sub package_extension_sql
 {
 	my ($extname, $extver) = @_;
@@ -1642,7 +1659,7 @@ sub upgrade_spatial_extensions
       $OPT_UPGRADE_TO = $defextver;
     }
 
-    my $nextver = $OPT_UPGRADE_TO ? "${OPT_UPGRADE_TO}" : "${libver}next";
+    my $nextver = $OPT_UPGRADE_TO ? "${OPT_UPGRADE_TO}" : "${libver}";
 
     if ( $upgrade_via_function )
     {
@@ -1654,7 +1671,7 @@ sub upgrade_spatial_extensions
     }
     else
     {
-      $sql = "ALTER EXTENSION postgis UPDATE TO '${nextver}'";
+        $sql = upgrade_extension_sql('postgis', ${libver}, ${nextver});
     }
 
     print "Upgrading PostGIS in '${DB}' using: ${sql}\n" ;
@@ -1709,10 +1726,13 @@ sub upgrade_spatial_extensions
 
     if ( $OPT_WITH_RASTER && has_split_raster_ext(${nextver}) )
     {
-        my $sql = "ALTER EXTENSION postgis_raster UPDATE TO '${nextver}'";
+        my $sql;
 
         if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
-					$sql = package_extension_sql('postgis_raster', ${nextver});
+            $sql = package_extension_sql('postgis_raster', ${nextver});
+        }
+        else {
+            $sql = upgrade_extension_sql('postgis_raster', ${libver}, ${nextver});
         }
 
         print "Upgrading PostGIS Raster in '${DB}' using: ${sql}\n" ;
@@ -1727,48 +1747,51 @@ sub upgrade_spatial_extensions
 
     if ( $OPT_WITH_TOPO )
     {
-      my $sql = "ALTER EXTENSION postgis_topology UPDATE TO '${nextver}'";
+        my $sql;
 
-			if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
-				$sql = package_extension_sql('postgis_topology', ${nextver});
-			}
+        if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+            $sql = package_extension_sql('postgis_topology', ${nextver});
+        }
+        else {
+            $sql = upgrade_extension_sql('postgis_topology', ${libver}, ${nextver});
+        }
 
-      print "Upgrading PostGIS Topology in '${DB}' using: ${sql}\n";
+        print "Upgrading PostGIS Topology in '${DB}' using: ${sql}\n";
 
-      my $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
-      my $rv = system($cmd);
-      if ( $rv ) {
-        fail "Error encountered updating EXTENSION POSTGIS_TOPOLOGY", $REGRESS_LOG;
-        die;
-      }
+        my $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+        my $rv = system($cmd);
+        if ( $rv ) {
+            fail "Error encountered updating EXTENSION POSTGIS_TOPOLOGY", $REGRESS_LOG;
+            die;
+        }
     }
 
     if ( $OPT_WITH_SFCGAL )
     {
-			my $sql;
+        my $sql;
 
-			if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
-				$sql = package_extension_sql('postgis_sfcgal', ${nextver});
-			}
-			elsif ( $OPT_UPGRADE_FROM && semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") )
-			{
-				print "NOTICE: installing SFCGAL extension on upgrade "
-						. "as it was not available in version '$OPT_UPGRADE_FROM'\n";
-				$sql = "CREATE EXTENSION postgis_sfcgal VERSION '${nextver}'";
-			}
-			else
-			{
-				$sql = "ALTER EXTENSION postgis_sfcgal UPDATE TO '${nextver}'";
-			}
-      $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+        if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+            $sql = package_extension_sql('postgis_sfcgal', ${nextver});
+        }
+        elsif ( $OPT_UPGRADE_FROM && semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") )
+        {
+            print "NOTICE: installing SFCGAL extension on upgrade "
+                . "as it was not available in version '$OPT_UPGRADE_FROM'\n";
+            $sql = "CREATE EXTENSION postgis_sfcgal VERSION '${nextver}'";
+        }
+        else
+        {
+            $sql = upgrade_extension_sql('postgis_sfcgal', ${libver}, ${nextver});
+        }
+        $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
 
-			print "Upgrading PostGIS SFCGAL in '${DB}' using: ${sql}\n" ;
+        print "Upgrading PostGIS SFCGAL in '${DB}' using: ${sql}\n" ;
 
-      $rv = system($cmd);
-      if ( $rv ) {
-        fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG;
-        die;
-      }
+        $rv = system($cmd);
+        if ( $rv ) {
+            fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG;
+            die;
+        }
     }
 
     return 1;

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

Summary of changes:
 NEWS                                        |   7 ++
 extensions/address_standardizer/Makefile.in |   5 ++
 extensions/upgrade-paths-rules.mk           |  33 +++++--
 loader/postgis.pl                           | 132 +++++++++++++++++++++++++++-
 postgis/postgis.sql.in                      |  36 ++------
 regress/run_test.pl                         |  95 ++++++++++++--------
 6 files changed, 235 insertions(+), 73 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list