[postgis-tickets] r17738 - Add support for :auto and :auto! upgrade-path targets in run_test.pl

Sandro Santilli strk at kbt.io
Tue Aug 20 08:17:14 PDT 2019


Author: strk
Date: 2019-08-20 08:17:14 -0700 (Tue, 20 Aug 2019)
New Revision: 17738

Modified:
   trunk/regress/run_test.pl
Log:
Add support for :auto and :auto! upgrade-path targets in run_test.pl

The former will request upgrading to default version, the latter
to do so using the postgis_extension_upgrade() function.

See #4485

Modified: trunk/regress/run_test.pl
===================================================================
--- trunk/regress/run_test.pl	2019-08-20 14:03:39 UTC (rev 17737)
+++ trunk/regress/run_test.pl	2019-08-20 15:17:14 UTC (rev 17738)
@@ -242,6 +242,7 @@
 }
 
 my $libver = sql("select postgis_lib_version()");
+my $defextver = sql("select default_version from pg_available_extensions where name = 'postgis'");
 
 if ( ! $libver )
 {
@@ -542,7 +543,13 @@
   -v, --verbose   be verbose about failures
   --nocreate      do not create the regression database on start
   --upgrade       source the upgrade scripts on start
-  --upgrade-path  upgrade path, format <from>--<to>
+  --upgrade-path  upgrade path, format <from>--<to>.
+                  <from> can be specified as "unpackaged<version>"
+                         to specify a script version to start from.
+                  <to> can be specified as ":auto" to request
+                       upgrades to default version, and ":auto!"
+                       to request upgrade via postgis_extensions_upgrade()
+                       if available.
   --dumprestore   dump and restore spatially-enabled db before running tests
   --nodrop        do not drop the regression database on exit
   --raster        load also raster extension
@@ -1504,12 +1511,35 @@
 {
     # ON_ERROR_STOP is used by psql to return non-0 on an error
     my $psql_opts = "--no-psqlrc --variable ON_ERROR_STOP=true";
+    my $sql;
+    my $upgrade_via_function = 0;
+
+    if ( $OPT_UPGRADE_TO =~ /^:auto/ )
+    {
+      if ( $OPT_UPGRADE_TO =~ /^:auto!/ )
+      {
+        if ( ! semver_lessthan($OPT_UPGRADE_FROM, "2.5.0") )
+        {
+          $upgrade_via_function = 1;
+        }
+      }
+      $OPT_UPGRADE_TO = $defextver;
+    }
+
     my $nextver = $OPT_UPGRADE_TO ? "${OPT_UPGRADE_TO}" : "${libver}next";
-    my $sql = "ALTER EXTENSION postgis UPDATE TO '${nextver}'";
 
-    if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+    if ( $upgrade_via_function )
+    {
+      $sql = "SELECT postgis_extensions_upgrade()";
+    }
+    elsif ( $OPT_UPGRADE_FROM =~ /^unpackaged/ )
+    {
       $sql = "CREATE EXTENSION postgis VERSION '${nextver}' FROM unpackaged";
     }
+    else
+    {
+      $sql = "ALTER EXTENSION postgis UPDATE TO '${nextver}'";
+    }
 
     print "Upgrading PostGIS in '${DB}' using: ${sql}\n" ;
 
@@ -1521,6 +1551,12 @@
       die;
     }
 
+    if ( $upgrade_via_function )
+    {
+      # The function does everything
+      return 1;
+    }
+
     if ( $OPT_WITH_RASTER )
     {
       if ( $OPT_UPGRADE_FROM



More information about the postgis-tickets mailing list