[postgis-tickets] r16731 - Only expliclty create/upgrade RASTER extension when split extension exists

Sandro Santilli strk at kbt.io
Tue Sep 11 02:18:31 PDT 2018


Author: strk
Date: 2018-09-11 02:18:31 -0700 (Tue, 11 Sep 2018)
New Revision: 16731

Modified:
   trunk/regress/run_test.pl
Log:
Only expliclty create/upgrade RASTER extension when split extension exists

Modified: trunk/regress/run_test.pl
===================================================================
--- trunk/regress/run_test.pl	2018-09-11 09:18:26 UTC (rev 16730)
+++ trunk/regress/run_test.pl	2018-09-11 09:18:31 UTC (rev 16731)
@@ -108,11 +108,18 @@
 
 if ( $OPT_EXTENSIONS )
 {
-	$OPT_WITH_RASTER = 1; # implied
+	$OPT_WITH_RASTER = 1; # implied (TODO: drop implication !)
 }
 
+sub has_split_raster_ext
+{
+  my $fullver = shift;
+  my @ver = split(/\./, $fullver);
+  return 0 if ( $ver[0] < 2 );
+  return 0 if ( $ver[0] == 2 && $ver[1] < 5 );
+  return 1;
+}
 
-
 ##################################################################
 # Set the locale to "C" so error messages match
 # Save original locale to set back
@@ -143,21 +150,6 @@
 
 print "PATH is $PATH\n";
 
-#foreach my $exec ( ("psql", "createdb", "createlang", "dropdb") )
-#{
-#	my $execdir = which( $exec );
-#	print "Checking for $exec ... ";
-#	if ( $execdir )
-#	{
-#		print "found $execdir\n";
-#	}
-#	else
-#	{
-#		print "failed\n";
-#		die "Unable to find $exec executable. Please ensure it is on your PATH.\n";
-#	}
-#}
-
 foreach my $exec ( ($SHP2PGSQL, $PGSQL2SHP) )
 {
 	printf "Checking for %s ... ", basename($exec);
@@ -213,7 +205,6 @@
 # Report
 print "TMPDIR is $TMPDIR\n";
 
-
 ##################################################################
 # Prepare the database
 ##################################################################
@@ -242,8 +233,8 @@
 	}
 	else
 	{
-		print "Database $DB already exists.\n";
-		print "Drop it, or run with the --nocreate flag to use it.\n";
+		print STDERR "Database $DB already exists.\n";
+		print STDERR "Drop it, or run with the --nocreate flag to use it.\n";
 		exit(1);
 	}
 }
@@ -1270,7 +1261,7 @@
 		if ( $rv )
 		{
 		  fail "Error encountered loading $file", $REGRESS_LOG;
-		  exit 1
+		  exit 1;
 		}
 	}
 	return 1;
@@ -1317,7 +1308,12 @@
 		}
  	}
 
-	if ( $OPT_WITH_RASTER )
+	if ( $OPT_WITH_RASTER && (
+		# NOTE: this code is assuming that the default version
+		# (!$OPT_UPGRADE_FROM) has split raster extension
+		! $OPT_UPGRADE_FROM ||
+		has_split_raster_ext($OPT_UPGRADE_FROM)
+	) )
 	{
 		my $sql = "CREATE EXTENSION postgis_raster";
 		if ( $OPT_UPGRADE_FROM ) {
@@ -1325,9 +1321,9 @@
 		}
  		$cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
 		$rv = system($cmd);
-  	if ( $rv ) {
-  		fail "Error encountered creating EXTENSION POSTGIS_RASTER", $REGRESS_LOG;
-  		die;
+		if ( $rv ) {
+			fail "Error encountered creating EXTENSION POSTGIS_RASTER", $REGRESS_LOG;
+			die;
 		}
  	}
 
@@ -1482,6 +1478,34 @@
       die;
     }
 
+    if ( $OPT_WITH_RASTER )
+    {
+      if ( $OPT_UPGRADE_FROM
+           && !  has_split_raster_ext($OPT_UPGRADE_FROM)
+         )
+      {
+        # upgrade of postgis must have unpackaged raster, so
+        # we create it again here
+        my $sql = "CREATE EXTENSION postgis_raster VERSION '${nextver}' FROM unpackaged";
+        my $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+        my $rv = system($cmd);
+        if ( $rv ) {
+          fail "Error encountered creating EXTENSION POSTGIS_RASTER from unpackaged on upgrade", $REGRESS_LOG;
+          die;
+        }
+      }
+      else
+      {
+        my $sql = "ALTER EXTENSION postgis_raster UPDATE TO '${nextver}'";
+        my $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+        my $rv = system($cmd);
+        if ( $rv ) {
+          fail "Error encountered altering EXTENSION POSTGIS_RASTER", $REGRESS_LOG;
+          die;
+        }
+      }
+    }
+
     if ( $OPT_WITH_TOPO )
     {
       my $sql = "ALTER EXTENSION postgis_topology UPDATE TO '${nextver}'";
@@ -1578,10 +1602,8 @@
 
     if ( $OPT_WITH_RASTER )
     {
-        $cmd = "psql $psql_opts -c \"DROP EXTENSION postgis_raster;\" $DB >> $REGRESS_LOG 2>&1";
+        $cmd = "psql $psql_opts -c \"DROP EXTENSION IF EXISTS postgis_raster;\" $DB >> $REGRESS_LOG 2>&1";
         $rv = system($cmd);
-        die "\nError encountered dropping EXTENSION POSTGIS_RASTER, see $REGRESS_LOG for details\n\n"
-            if $rv;
       	$ok = 0 if $rv;
     }
 



More information about the postgis-tickets mailing list