[postgis-tickets] [SCM] PostGIS branch stable-2.5--run_test created. 2.5.7-5-g2b4e86a8d
git at osgeo.org
git at osgeo.org
Sun Aug 7 08:57:15 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, stable-2.5--run_test has been created
at 2b4e86a8da32190f6edbca11e215528f27b83c22 (commit)
- Log -----------------------------------------------------------------
commit 2b4e86a8da32190f6edbca11e215528f27b83c22
Author: Sandro Santilli <strk at kbt.io>
Date: Sun Aug 7 17:56:54 2022 +0200
Copy run_test.pl from master branch
diff --git a/regress/run_test.pl b/regress/run_test.pl
index e95f1534c..efafb29ae 100755
--- a/regress/run_test.pl
+++ b/regress/run_test.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
#
# PostGIS - Spatial Types for PostgreSQL
@@ -15,6 +15,7 @@
#$| = 1;
use File::Basename;
use File::Temp 'tempdir';
+use Time::HiRes qw(time);
#use File::Which;
use File::Copy;
use File::Path;
@@ -38,6 +39,9 @@ BEGIN {
#
# Run the <testname>.sql script
# Check output against <testname>_expected
+#
+# Use `-` as the testname to drop into an interactive shell
+#
##################################################################
##################################################################
@@ -46,9 +50,10 @@ BEGIN {
our $DB = $ENV{"POSTGIS_REGRESS_DB"} || "postgis_reg";
our $REGDIR = abs_path(dirname($0));
-our $SHP2PGSQL = $REGDIR . "/../loader/shp2pgsql";
-our $PGSQL2SHP = $REGDIR . "/../loader/pgsql2shp";
-our $RASTER2PGSQL = $REGDIR . "/../raster/loader/raster2pgsql";
+our $TOP_BUILDDIR = $ENV{"POSTGIS_TOP_BUILD_DIR"} || ${REGDIR} . '/..';
+our $SHP2PGSQL = $TOP_BUILDDIR . "/loader/shp2pgsql";
+our $PGSQL2SHP = $TOP_BUILDDIR . "/loader/pgsql2shp";
+our $RASTER2PGSQL = $TOP_BUILDDIR . "/raster/loader/raster2pgsql";
our $sysdiff = !system("diff --strip-trailing-cr $0 $0 2> /dev/null");
##################################################################
@@ -60,17 +65,22 @@ my $OPT_NODROP = 0;
my $OPT_NOCREATE = 0;
my $OPT_UPGRADE = 0;
my $OPT_DUMPRESTORE = 0;
+my $OPT_WITH_TIGER = 0;
my $OPT_WITH_TOPO = 0;
my $OPT_WITH_RASTER = 0;
my $OPT_WITH_SFCGAL = 0;
my $OPT_EXPECT = 0;
my $OPT_EXTENSIONS = 0;
+my @OPT_HOOK_AFTER_CREATE;
+my @OPT_HOOK_BEFORE_UNINSTALL;
+my @OPT_HOOK_BEFORE_UPGRADE;
+my @OPT_HOOK_AFTER_UPGRADE;
my $OPT_EXTVERSION = '';
my $OPT_UPGRADE_PATH = '';
our $OPT_UPGRADE_FROM = '';
my $OPT_UPGRADE_TO = '';
-my $VERBOSE = 0;
-my $OPT_SCHEMA = 'public';
+our $VERBOSE = 0;
+our $OPT_SCHEMA = 'public';
GetOptions (
'verbose' => \$VERBOSE,
@@ -80,12 +90,17 @@ GetOptions (
'upgrade-path=s' => \$OPT_UPGRADE_PATH,
'dumprestore' => \$OPT_DUMPRESTORE,
'nocreate' => \$OPT_NOCREATE,
+ 'tiger' => \$OPT_WITH_TIGER,
'topology' => \$OPT_WITH_TOPO,
'raster' => \$OPT_WITH_RASTER,
'sfcgal' => \$OPT_WITH_SFCGAL,
'expect' => \$OPT_EXPECT,
'extensions' => \$OPT_EXTENSIONS,
- 'schema=s' => \$OPT_SCHEMA
+ 'schema=s' => \$OPT_SCHEMA,
+ 'after-create-script=s' => \@OPT_HOOK_AFTER_CREATE,
+ 'before-uninstall-script=s' => \@OPT_HOOK_BEFORE_UNINSTALL,
+ 'before-upgrade-script=s' => \@OPT_HOOK_BEFORE_UPGRADE,
+ 'after-upgrade-script=s' => \@OPT_HOOK_AFTER_UPGRADE
);
if ( @ARGV < 1 )
@@ -95,10 +110,6 @@ if ( @ARGV < 1 )
if ( $OPT_UPGRADE_PATH )
{
- if ( ! $OPT_EXTENSIONS )
- {
- die "--upgrade-path is only supported with --extension"
- }
$OPT_UPGRADE = 1; # implied
my @path = split ('--', $OPT_UPGRADE_PATH);
$OPT_UPGRADE_FROM = $path[0]
@@ -108,13 +119,18 @@ if ( $OPT_UPGRADE_PATH )
print "Upgrade path: ${OPT_UPGRADE_FROM} --> ${OPT_UPGRADE_TO}\n";
}
-if ( $OPT_EXTENSIONS )
+# Split-raster extension was introduced in PostGIS-3.0.0
+sub has_split_raster_ext
{
- $OPT_WITH_RASTER = 1; # implied
+ my $fullver = shift;
+ # unpackaged is always current, so does have
+ # split raster already.
+ return 1 if $fullver =~ /^unpackaged/;
+ my @ver = split(/\./, $fullver);
+ return 0 if ( $ver[0] < 3 );
+ return 1;
}
-
-
##################################################################
# Set the locale to "C" so error messages match
# Save original locale to set back
@@ -137,7 +153,7 @@ $ENV{"PGOPTIONS"} = $PGOPTIONS;
my $PATH = $ENV{"PATH"}; # this is useless
# Calculate the regression directory locations
-my $STAGED_INSTALL_DIR = $REGDIR . "/00-regress-install";
+my $STAGED_INSTALL_DIR = $TOP_BUILDDIR . "/regress/00-regress-install";
my $STAGED_SCRIPTS_DIR = $STAGED_INSTALL_DIR . "/share/contrib/postgis";
my $OBJ_COUNT_PRE = 0;
@@ -149,21 +165,6 @@ my $OBJ_COUNT_POST = 0;
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);
@@ -174,7 +175,8 @@ foreach my $exec ( ($SHP2PGSQL, $PGSQL2SHP) )
else
{
print "failed\n";
- die "Unable to find $exec executable.\n";
+ print STDERR "Unable to find $exec executable.\n";
+ die "HINT: set POSTGIS_TOP_BUILD_DIR env variable to the build dir.\n";
}
}
@@ -219,12 +221,17 @@ my $REGRESS_LOG = "${TMPDIR}/regress_log";
# Report
print "TMPDIR is $TMPDIR\n";
-
##################################################################
# Prepare the database
##################################################################
-my @dblist = grep(/\b$DB\b/, split(/\n/, `psql -Xl`));
+my @dblist = grep(/1/, split(/\n/, `
+psql -tAc "
+ SELECT 1 FROM pg_catalog.pg_database
+ WHERE datname = '${DB}'
+" template1
+`));
+
my $dbcount = @dblist;
if ( $dbcount == 0 )
@@ -248,13 +255,15 @@ else
}
else
{
- print "Database $DB already exists.\n";
- print "Drop it, or run with the --nocreate flag to use it.\n";
- exit(1);
+ print STDERR "Database $DB already exists, dropping.\n";
+ `dropdb $DB`;
+ create_spatial();
}
}
+my $pgvernum = sql("SELECT current_setting('server_version_num')");
my $libver = sql("select postgis_lib_version()");
+my $defextver = sql("select default_version from pg_available_extensions where name = 'postgis'");
if ( ! $libver )
{
@@ -264,6 +273,23 @@ if ( ! $libver )
exit(1);
}
+sub scriptdir
+{
+ my ( $version, $systemwide ) = @_;
+ my $scriptdir;
+ if ( $systemwide or ( $version and $version ne $libver ) ) {
+ my $pgis_majmin = $version;
+ $pgis_majmin =~ s/^([1-9]*\.[0-9]*).*/\1/;
+ $scriptdir = `pg_config --sharedir`;
+ chop $scriptdir;
+ $scriptdir .= "/contrib/postgis-" . $pgis_majmin;
+ } else {
+ $scriptdir = $STAGED_SCRIPTS_DIR;
+ }
+ #print "XXX: scriptdir: $scriptdir\n";
+ return $scriptdir;
+}
+
sub semver_lessthan
{
my ($a,$b) = @_;
@@ -280,79 +306,15 @@ sub semver_lessthan
return @bcomp ? 1 : 0;
}
-sub create_upgrade_test_objects
-{
- # TODO: allow passing the "upgrade-init" script via commandline
-
- my $query = "create table upgrade_test(g1 geometry, g2 geography";
- $query .= ", r raster" if ( $OPT_WITH_RASTER );
- $query .= ")";
- my $ret = sql($query);
- unless ( $ret =~ /^CREATE/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong creating upgrade_test table: $ret.\n";
- exit(1);
- }
-
- if ( $OPT_WITH_RASTER )
- {
- $query = "UPDATE upgrade_test SET r = ";
- $query .= " ST_AddBand(ST_MakeEmptyRaster(10, 10, 1, 1, 2, 2, 0, 0,4326), 1, '8BSI'::text, -129, NULL);";
- $ret = sql($query);
- unless ( $ret =~ /^UPDATE/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong setting raster into upgrade_test table: $ret.\n";
- exit(1);
- }
-
- $query = "set client_min_messages to error; select AddRasterConstraints('upgrade_test', 'r')";
- $ret = sql($query);
- unless ( $ret =~ /^t$/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong adding raster constraints to upgrade_test: " . $ret . "\n";
- exit(1);
- }
- }
-
- if ( $OPT_WITH_TOPO )
- {
- $query = "select topology.createTopology('upgrade_test');";
- $ret = sql($query);
- unless ( $ret =~ /^[1-9][0-9]*$/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong adding upgrade_test topology: " . $ret . "\n";
- exit(1);
- }
- }
-}
-
-sub drop_upgrade_test_objects
-{
- # TODO: allow passing the "upgrade-cleanup" script via commandline
-
- my $ret = sql("drop table upgrade_test;");
- unless ( $ret =~ /^DROP/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong dropping spatial tables: $ret.\n";
- exit(1);
- }
-
- if ( $OPT_WITH_TOPO )
- {
- my $query = "SELECT topology.DropTopology('upgrade_test');";
- $ret = sql($query);
- unless ( $ret =~ /^Topology 'upgrade_test' dropped$/ ) {
- `dropdb $DB`;
- print "\nSomething went wrong dropping upgrade_test topology: " . $ret . "\n";
- exit(1);
- }
- }
-}
-
-
if ( $OPT_UPGRADE )
{
- create_upgrade_test_objects();
+ print "Upgrading from postgis $libver\n";
+
+ foreach my $hook (@OPT_HOOK_BEFORE_UPGRADE)
+ {
+ print "Running before-upgrade-script $hook\n";
+ die unless load_sql_file($hook, 1);
+ }
if ( $OPT_EXTENSIONS )
{
@@ -363,7 +325,11 @@ if ( $OPT_UPGRADE )
upgrade_spatial();
}
- drop_upgrade_test_objects();
+ foreach my $hook (@OPT_HOOK_AFTER_UPGRADE)
+ {
+ print "Running after-upgrade-script $hook\n";
+ die unless load_sql_file($hook, 1);
+ }
# Update libver
$libver = sql("select postgis_lib_version()");
@@ -381,17 +347,20 @@ if ( $OPT_DUMPRESTORE )
my $geosver = sql("select postgis_geos_version()");
my $projver = sql("select postgis_proj_version()");
-my $svnrev = sql("select postgis_svn_version()");
my $libbuilddate = sql("select postgis_lib_build_date()");
my $pgsqlver = sql("select version()");
my $gdalver = sql("select postgis_gdal_version()") if $OPT_WITH_RASTER;
my $sfcgalver = sql("select postgis_sfcgal_version()") if $OPT_WITH_SFCGAL;
my $scriptver = sql("select postgis_scripts_installed()");
+# postgis_lib_revision was introduced in 3.1.0
+my $librev = semver_lessthan($scriptver, "3.1.0") ?
+ sql("select postgis_svn_version()") :
+ sql("select postgis_lib_revision()");
my $raster_scriptver = sql("select postgis_raster_scripts_installed()")
if ( $OPT_WITH_RASTER );
print "$pgsqlver\n";
-print " Postgis $libver - r${svnrev} - $libbuilddate\n";
+print " Postgis $libver - (${librev}) - $libbuilddate\n";
print " scripts ${scriptver}\n";
print " raster scripts ${raster_scriptver}\n" if ( $OPT_WITH_RASTER );
print " GEOS: $geosver\n" if $geosver;
@@ -414,15 +383,51 @@ our $TEST = "";
print "\nRunning tests\n\n";
+foreach my $hook (@OPT_HOOK_AFTER_CREATE)
+{
+ start_test("after-create-script $hook");
+ show_progress();
+ pass() if load_sql_file($hook, 1);
+}
+
foreach $TEST (@ARGV)
{
+ my $TEST_OBJ_COUNT_PRE;
+ my $TEST_OBJ_COUNT_POST;
+ my $TEST_START_TIME;
+
+ if ( "${TEST}" eq '-' )
+ {
+ my $scriptdir = scriptdir($libver, $OPT_EXTENSIONS);
+ print "-- Entering interactive shell --\n";
+ # TODO: add more variables?
+ my $cmd = "psql -Xq"
+ . " -v \"regdir=$REGDIR\""
+ . " -v \"top_builddir=$TOP_BUILDDIR\""
+ . " -v \"scriptdir=$scriptdir\""
+ . " -v \"schema=$OPT_SCHEMA.\""
+ # TODO: inject search_path somehow
+ #. " -c \"SET search_path TO public,$OPT_SCHEMA,topology\""
+ . " ${DB}"
+ ;
+ my $rv = system($cmd);
+ print "-- Moving on with tests, if any --\n";
+ next;
+ }
+
# catch a common mistake (strip trailing .sql)
$TEST =~ s/.sql$//;
start_test($TEST);
+ $TEST_OBJ_COUNT_PRE = count_postgis_objects();
# Check for a "-pre.pl" file in case there are setup commands
- eval_file("${TEST}-pre.pl");
+ unless ( eval_file("${TEST}-pre.pl") )
+ {
+ chop($@);
+ fail("Failed evaluating ${TEST}-pre.pl: $@");
+ next;
+ }
# Check for a "-pre.sql" file in case there is setup SQL needed before
# the test can be run.
@@ -436,23 +441,37 @@ foreach $TEST (@ARGV)
# create the .sql
# Check for .dbf not just .shp since the loader can load
# .dbf files without a .shp.
+ $TEST_START_TIME = time;
if ( -r "${TEST}.dbf" )
{
- pass() if ( run_loader_test() );
+ pass("in ".int(1000*(time-$TEST_START_TIME))." ms") if ( run_loader_test() );
}
elsif ( -r "${TEST}.tif" )
{
- my $rv = run_raster_loader_test();
- pass() if $rv;
+ my $rv = run_raster_loader_test("${TEST}.tif");
+ pass("in ".int(1000*(time-$TEST_START_TIME))." ms") if $rv;
+ }
+ elsif ( -r "${TEST}.tif.ref" )
+ {
+ open(REF, "${TEST}.tif.ref");
+ my $raster_ref = <REF>;
+ close(REF);
+ chop $raster_ref;
+ #print "Raster ref: [$raster_ref]\n";
+ # Resolve raster_ref relative to ${TEST} dirname
+ my $raster_path = dirname(${TEST}) . '/' . $raster_ref;
+ #print "Raster path: [$raster_path]\n";
+ my $rv = run_raster_loader_test($raster_path);
+ pass("in ".int(1000*(time-$TEST_START_TIME))." ms") if $rv;
}
elsif ( -r "${TEST}.sql" )
{
my $rv = run_simple_test("${TEST}.sql", "${TEST}_expected");
- pass() if $rv;
+ pass("in ".int(1000*(time-$TEST_START_TIME))." ms") if $rv;
}
elsif ( -r "${TEST}.dmp" )
{
- pass() if run_dumper_test();
+ pass("in ".int(1000*(time-$TEST_START_TIME))." ms") if run_dumper_test();
}
else
{
@@ -472,8 +491,22 @@ foreach $TEST (@ARGV)
}
# Check for a "-post.pl" file in case there are teardown commands
- eval_file("${TEST}-post.pl");
+ eval_file("${TEST}-post.pl");
+
+ $TEST_OBJ_COUNT_POST = count_postgis_objects();
+
+ if ( $TEST_OBJ_COUNT_POST != $TEST_OBJ_COUNT_PRE )
+ {
+ fail("PostGIS object count pre-test ($TEST_OBJ_COUNT_POST) != post-test ($TEST_OBJ_COUNT_PRE)");
+ }
+
+}
+foreach my $hook (@OPT_HOOK_BEFORE_UNINSTALL)
+{
+ start_test("before-uninstall-script $hook");
+ show_progress();
+ pass() if load_sql_file($hook, 1);
}
@@ -505,7 +538,6 @@ if ( $OPT_CLEAN )
if ( ! ($OPT_NODROP || $OPT_NOCREATE) )
{
- sleep(1);
system("dropdb $DB");
}
else
@@ -533,15 +565,37 @@ Options:
-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 be appended
+ an exclamation mark (ie: ":auto!" or "3.0.0!") 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
+ --schema where to install/find PostGIS (relocatable) PostGIS
+ (defaults to "public")
--raster load also raster extension
+ --tiger load also tiger_geocoder extension
--topology load also topology extension
--sfcgal use also sfcgal backend
--clean cleanup test logs on exit
--expect save obtained output as expected
--extension load using extensions
+ --after-create-script <path>
+ script to load after spatial db creation
+ (multiple switches supported, to be run in given order)
+ --before-uninstall-script <path>
+ script to load before spatial extension uninstall
+ (multiple switches supported, to be run in given order)
+ --before-upgrade-script <path>
+ script to load before upgrade
+ (multiple switches supported, to be run in given order)
+ --after-upgrade-script <path>
+ script to load after upgrade
+ (multiple switches supported, to be run in given order)
};
}
@@ -571,8 +625,8 @@ sub show_progress
# pass <msg>
sub pass
{
- my $msg = shift;
- printf(" ok %s\n", $msg);
+ my $msg = shift;
+ printf(" ok %s\n", $msg);
}
# fail <msg> <log>
@@ -621,7 +675,10 @@ sub run_simple_sql
# Dump output to a temp file.
my $tmpfile = sprintf("%s/test_%s_tmp", $TMPDIR, $RUN);
- my $cmd = "psql -v \"VERBOSITY=terse\" -tXA $DB < $sql > $tmpfile 2>&1";
+ my $cmd = "psql -v \"VERBOSITY=terse\" "
+ . " -v \"regdir=$REGDIR\""
+ . " -v \"top_builddir=$TOP_BUILDDIR\""
+ . " -tXAq $DB < $sql > $tmpfile 2>&1";
#print($cmd);
my $rv = system($cmd);
# Check if psql errored out.
@@ -650,7 +707,7 @@ sub run_simple_sql
sub drop_table
{
my $tblname = shift;
- my $cmd = "psql -tXA -d $DB -c \"DROP TABLE IF EXISTS $tblname\" >> $REGRESS_LOG 2>&1";
+ my $cmd = "psql -tXAq -d $DB -c \"DROP TABLE IF EXISTS $tblname\" >> $REGRESS_LOG 2>&1";
my $rv = system($cmd);
die "Could not run: $cmd\n" if $rv;
}
@@ -658,7 +715,7 @@ sub drop_table
sub sql
{
my $sql = shift;
- my $result = `psql -tXA -d $DB -c "$sql"`;
+ my $result = `psql -tXA -d $DB -c 'SET search_path TO public,$OPT_SCHEMA' -c "$sql" | sed '/^SET\$/d'`;
$result =~ s/[\n\r]*$//;
$result;
}
@@ -669,12 +726,10 @@ sub eval_file
my $pl;
if ( -r $file )
{
- #open(PL, $file);
- #$pl = <PL>;
- #close(PL);
- #eval($pl);
- do $file;
+ do $file or return 0;
+ #system($^X, $file) == 0 or return 0;
}
+ 1;
}
##################################################################
@@ -713,24 +768,22 @@ sub run_simple_test
mkpath($betmpdir);
chmod 0777, $betmpdir;
- my $scriptdir;
- if ( $OPT_EXTENSIONS ) {
- # TODO: allow override this default with env variable ?
- my $pgis_majmin = $libver;
- $pgis_majmin =~ s/^([1-9]*\.[1-9]*).*/\1/;
- $scriptdir = `pg_config --sharedir`;
- chop $scriptdir;
- $scriptdir .= "/contrib/postgis-" . $pgis_majmin;
- } else {
- $scriptdir = $STAGED_SCRIPTS_DIR;
- }
- my $cmd = "psql -v \"VERBOSITY=terse\""
+ my $scriptdir = scriptdir($libver, $OPT_EXTENSIONS);
+
+ my ($sqlfile,$sqldir) = fileparse($sql);
+ my $cmd = "cd $sqldir; psql -v \"VERBOSITY=terse\""
. " -v \"tmpfile='$tmpfile'\""
. " -v \"scriptdir=$scriptdir\""
. " -v \"regdir=$REGDIR\""
+ . " -v \"top_builddir=$TOP_BUILDDIR\""
. " -v \"schema=$OPT_SCHEMA.\""
- . " -tXA $DB < $sql > $outfile 2>&1";
+ . " -c \"SET search_path TO public,$OPT_SCHEMA,topology\""
+ . " -tXAq -f $sqlfile $DB > $outfile 2>&1";
my $rv = system($cmd);
+ if ( $rv ) {
+ fail "psql exited with an error", $outfile;
+ die;
+ }
# Check for ERROR lines
open(FILE, "$outfile");
@@ -739,7 +792,7 @@ sub run_simple_test
# Strip the lines we don't care about
@lines = grep(!/^\$/, @lines);
- @lines = grep(!/^(INSERT|DELETE|UPDATE|SELECT|COPY|DO)/, @lines);
+ @lines = grep(!/^(INSERT|DELETE|UPDATE|SELECT [0-9]*|COPY|DO)$/, @lines);
@lines = grep(!/^(CONTEXT|RESET|ANALYZE)/, @lines);
@lines = grep(!/^(DROP|CREATE|ALTER|VACUUM)/, @lines);
@lines = grep(!/^(LOG|SET|TRUNCATE|DISCARD)/, @lines);
@@ -837,7 +890,7 @@ sub run_loader_and_check_output
if ( $rv )
{
- fail(" $description: running shp2pgsql", "$errfile");
+ fail(" $description: running $cmd", "$errfile");
return 0;
}
@@ -946,6 +999,7 @@ sub run_dumper_and_check_output
sub run_raster_loader_and_check_output
{
my $description = shift;
+ my $raster_file = shift;
my $tblname = shift;
my $expected_sql_file = shift;
my $expected_select_results_file = shift;
@@ -964,7 +1018,7 @@ sub run_raster_loader_and_check_output
show_progress();
# Produce the output SQL file.
- $cmd = "$RASTER2PGSQL $loader_options ${TEST}.tif $tblname > $outfile 2> $errfile";
+ $cmd = "$RASTER2PGSQL $loader_options $raster_file $tblname > $outfile 2> $errfile";
$rv = system($cmd);
if ( $rv )
@@ -1025,10 +1079,14 @@ sub run_loader_test
if ( -r $opts_file )
{
open(FILE, $opts_file);
- my @opts = <FILE>;
+ my @opts;
+ while (<FILE>) {
+ next if /^\s*#/;
+ chop;
+ s/{regdir}/$REGDIR/;
+ push @opts, $_;
+ }
close(FILE);
- @opts = grep(!/^\s*#/, @opts);
- map(s/\n//, @opts);
$custom_opts = join(" ", @opts);
}
@@ -1037,6 +1095,7 @@ sub run_loader_test
# If we have some expected files to compare with, run in wkt mode.
if ( ! run_loader_and_check_output("wkt test", $tblname, "${TEST}-w.sql.expected", "${TEST}-w.select.expected", "-w $custom_opts") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1044,11 +1103,13 @@ sub run_loader_test
# If we have some expected files to compare with, run in geography mode.
if ( ! run_loader_and_check_output("geog test", $tblname, "${TEST}-G.sql.expected", "${TEST}-G.select.expected", "-G $custom_opts") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
# If we have some expected files to compare with, run the dumper and compare shape files.
if ( ! run_dumper_and_check_output("dumper geog test", $tblname, "${TEST}-G.shp.expected") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1056,11 +1117,13 @@ sub run_loader_test
# Always run in wkb ("normal") mode, even if there are no expected files to compare with.
if( ! run_loader_and_check_output("wkb test", $tblname, "${TEST}.sql.expected", "${TEST}.select.expected", "$custom_opts", "true") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
# If we have some expected files to compare with, run the dumper and compare shape files.
if( ! run_dumper_and_check_output("dumper wkb test", $tblname, "${TEST}.shp.expected") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1071,6 +1134,7 @@ sub run_loader_test
# If we have some expected files to compare with, run in wkt dump mode.
if ( ! run_loader_and_check_output("wkt dump test", $tblname, "${TEST}-wD.sql.expected") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1078,6 +1142,7 @@ sub run_loader_test
# If we have some expected files to compare with, run in wkt dump mode.
if ( ! run_loader_and_check_output("geog dump test", $tblname, "${TEST}-GD.sql.expected") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1085,6 +1150,7 @@ sub run_loader_test
# If we have some expected files to compare with, run in wkb dump mode.
if ( ! run_loader_and_check_output("wkb dump test", $tblname, "${TEST}-D.sql.expected") )
{
+ drop_table($tblname) unless $OPT_NODROP;
return 0;
}
drop_table($tblname);
@@ -1099,9 +1165,9 @@ sub run_loader_test
# Run dumper and compare output with various expectances
# test and run simple test with provided expected output.
#
-# input is ${TEST}.dmp, where last line is considered to be the
-# [table|query] argument for pgsql2shp and all the previous lines,
-# if any are
+# input is ${TEST}.dmp, where first line is considered to be the
+# [table|query] argument for pgsql2shp and all the next lines,
+# if any are options.
#
##################################################################
sub run_dumper_test
@@ -1117,12 +1183,16 @@ sub run_dumper_test
# Produce the output SHP file.
open DUMPFILE, "$dump_file" or die "Cannot open dump file $dump_file\n";
- sleep(1);
my @dumplines = <DUMPFILE>;
close DUMPFILE;
- my $dumpstring = join '', @dumplines;
- chop($dumpstring);
- my @cmd = ("${PGSQL2SHP}", "-f", ${shpfile}, ${DB}, ${dumpstring});
+ chomp(@dumplines);
+ my $dumpstring = shift @dumplines;
+ @dumplines = map { local $_ = $_; s/{regdir}/$REGDIR/; $_ } @dumplines;
+ my @cmd = ("${PGSQL2SHP}", "-f", ${shpfile});
+ push @cmd, @dumplines;
+ push @cmd, ${DB};
+ push @cmd, $dumpstring;
+ #print "CMD: " . join (' ', @cmd) . "\n";
open my $stdout_save, '>&', *STDOUT or die "Cannot dup stdout\n";
open my $stderr_save, '>&', *STDERR or die "Cannot dup stdout\n";
open STDOUT, ">${outfile}" or die "Cannot write to ${outfile}\n";
@@ -1130,7 +1200,6 @@ sub run_dumper_test
my $rv = system(@cmd);
open STDERR, '>&', $stderr_save;
open STDOUT, '>&', $stdout_save;
- #sleep(3);
show_progress();
if ( $rv )
@@ -1182,24 +1251,30 @@ sub run_dumper_test
##################################################################
sub run_raster_loader_test
{
+ my $raster_file = shift;
# See if there is a custom command-line options file
my $opts_file = "${TEST}.opts";
my $custom_opts="";
if ( -r $opts_file )
{
+ my $regdir = abs_path(dirname(${TEST}));
open(FILE, $opts_file);
- my @opts = <FILE>;
+ my @opts;
+ while (<FILE>) {
+ next if /^\s*#/;
+ chop;
+ s/{regdir}/$regdir/;
+ push @opts, $_;
+ }
close(FILE);
- @opts = grep(!/^\s*#/, @opts);
- map(s/\n//, @opts);
$custom_opts = join(" ", @opts);
}
my $tblname="loadedrast";
# If we have some expected files to compare with, run in geography mode.
- if ( ! run_raster_loader_and_check_output("test", $tblname, "${TEST}.sql.expected", "${TEST}.select.expected", $custom_opts, "true") )
+ if ( ! run_raster_loader_and_check_output("test", $raster_file, $tblname, "${TEST}.sql.expected", "${TEST}.select.expected", $custom_opts, "true") )
{
return 0;
}
@@ -1223,42 +1298,74 @@ sub count_db_objects
select count(*) from pg_operator union all
select count(*) from pg_opclass union all
select count(*) from pg_namespace
- where nspname NOT LIKE 'pg_%' union all
- select count(*) from pg_opfamily )
+ where nspname NOT LIKE 'pg_%'
+ and nspname != '${OPT_SCHEMA}'
+ union all
+ select count(*) from pg_opfamily
+ )
+ select sum(count) from counts");
+
+ return $count;
+}
+
+
+##################################################################
+# Count postgis objects
+##################################################################
+sub count_postgis_objects
+{
+ my $count = sql("WITH counts as (
+ select count(*) from spatial_ref_sys
+ )
select sum(count) from counts");
return $count;
}
+
##################################################################
# Create the spatial database
##################################################################
sub create_db
{
- my $cmd = "createdb --encoding=UTF-8 --template=template0 --lc-collate=C $DB > $REGRESS_LOG";
- return system($cmd);
+ my $createcmd = "createdb --encoding=UTF-8 --template=template0 --lc-collate=C $DB > $REGRESS_LOG";
+ return system($createcmd);
}
sub create_spatial
{
- my ($cmd, $rv);
- print "Creating database '$DB' \n";
+ my ($cmd, $rv);
+ print "Creating database '$DB' \n";
- $rv = create_db();
+ $rv = create_db();
+ # Count database objects before installing anything
+ $OBJ_COUNT_PRE = count_db_objects();
- # Count database objects before installing anything
- $OBJ_COUNT_PRE = count_db_objects();
+ if ( $OPT_EXTENSIONS )
+ {
+ prepare_spatial_extensions();
+ }
+ else
+ {
+ if ( ! $OPT_UPGRADE_FROM )
+ {
+ prepare_spatial();
+ return;
+ }
- if ( $OPT_EXTENSIONS )
- {
- prepare_spatial_extensions();
- }
- else
- {
- prepare_spatial();
- }
+ if ( $OPT_UPGRADE_FROM !~ /^unpackaged(.*)/ )
+ {
+ die "--upgrade-path without --extension is only supported with source unpackaged*";
+ }
+
+ if ( $OPT_UPGRADE_TO != ':auto' )
+ {
+ die "--upgrade-path without --extension is only supported with target :auto";
+ }
+ prepare_spatial($1);
+ }
}
@@ -1269,20 +1376,24 @@ sub load_sql_file
if ( $strict && ! -e $file )
{
- die "Unable to find $file\n";
+ fail "Unable to find $file";
+ return 0;
}
if ( -e $file )
{
# 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 $cmd = "psql $psql_opts -Xf $file $DB >> $REGRESS_LOG 2>&1";
- print " $file\n" if $VERBOSE;
+ my $cmd = "psql $psql_opts -c 'CREATE SCHEMA IF NOT EXISTS $OPT_SCHEMA' ";
+ $cmd .= "-c 'SET search_path TO $OPT_SCHEMA,topology'";
+ $cmd .= " -Xf $file $DB >> $REGRESS_LOG 2>&1";
+ #print " $file\n" if $VERBOSE;
my $rv = system($cmd);
if ( $rv )
{
fail "Error encountered loading $file", $REGRESS_LOG;
- exit 1
+ #exit 1;
+ return 0;
}
}
return 1;
@@ -1293,15 +1404,27 @@ sub prepare_spatial_extensions
{
# 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 = "CREATE SCHEMA IF NOT EXISTS ${OPT_SCHEMA}";
+ my $cmd = "psql $psql_opts -c \"". $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+ my $rv = system($cmd);
+ if ( $rv ) {
+ fail "Error encountered creating target schema ${OPT_SCHEMA}", $REGRESS_LOG;
+ die;
+ }
+
my $sql = "CREATE EXTENSION postgis";
+
if ( $OPT_UPGRADE_FROM ) {
- if ( $OPT_UPGRADE_FROM eq "unpackaged" ) {
- prepare_spatial();
+ if ( $OPT_UPGRADE_FROM =~ /^unpackaged(.*)/ ) {
+ prepare_spatial($1);
return;
}
$sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'";
}
+ $sql .= " SCHEMA " . $OPT_SCHEMA;
+
print "Preparing db '${DB}' using: ${sql}\n";
my $cmd = "psql $psql_opts -c \"". $sql . "\" $DB >> $REGRESS_LOG 2>&1";
@@ -1329,9 +1452,50 @@ sub prepare_spatial_extensions
}
}
+ if ( $OPT_WITH_TIGER )
+ {
+ my $sql = "CREATE EXTENSION postgis_tiger_geocoder CASCADE";
+ if ( $OPT_UPGRADE_FROM ) {
+ $sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'";
+ }
+
+ print "Preparing db '${DB}' using: ${sql}\n";
+
+ $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+ $rv = system($cmd);
+ if ( $rv ) {
+ fail "Error encountered creating EXTENSION POSTGIS_TIGER_GEOCODER", $REGRESS_LOG;
+ die;
+ }
+ }
+
+ 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 ) {
+ $sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'";
+ }
+
+ $sql .= " SCHEMA " . $OPT_SCHEMA;
+
+ print "Preparing db '${DB}' using: ${sql}\n";
+
+ $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 ( $OPT_WITH_SFCGAL )
{
- do {
+ {
my $sql = "CREATE EXTENSION postgis_sfcgal";
if ( $OPT_UPGRADE_FROM ) {
if ( semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") )
@@ -1343,6 +1507,8 @@ sub prepare_spatial_extensions
$sql .= " VERSION '" . $OPT_UPGRADE_FROM . "'";
}
+ $sql .= " SCHEMA " . $OPT_SCHEMA;
+
print "Preparing db '${DB}' using: ${sql}\n";
$cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
@@ -1351,7 +1517,7 @@ sub prepare_spatial_extensions
fail "Error encountered creating EXTENSION POSTGIS_SFCGAL", $REGRESS_LOG;
die;
}
- } while (0);
+ }
}
return 1;
@@ -1360,99 +1526,83 @@ sub prepare_spatial_extensions
# Prepare the database for spatial operations (old method)
sub prepare_spatial
{
+ my $version = shift;
+ my $scriptdir = scriptdir($version);
+ print "Loading unpackaged components from $scriptdir\n";
+
print "Loading PostGIS into '${DB}' \n";
# Load postgis.sql into the database
- load_sql_file("${STAGED_SCRIPTS_DIR}/postgis.sql", 1);
- load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_comments.sql", 0);
- load_sql_file("${STAGED_SCRIPTS_DIR}/postgis_proc_set_search_path.sql", 0);
+ load_sql_file("${scriptdir}/postgis.sql", 1);
+ load_sql_file("${scriptdir}/postgis_comments.sql", 0);
+ load_sql_file("${scriptdir}/spatial_ref_sys.sql", 0);
if ( $OPT_WITH_TOPO )
{
print "Loading Topology into '${DB}'\n";
- load_sql_file("${STAGED_SCRIPTS_DIR}/topology.sql", 1);
- load_sql_file("${STAGED_SCRIPTS_DIR}/topology_comments.sql", 0);
+ load_sql_file("${scriptdir}/topology.sql", 1);
+ load_sql_file("${scriptdir}/topology_comments.sql", 0);
}
if ( $OPT_WITH_RASTER )
{
print "Loading Raster into '${DB}'\n";
- load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis.sql", 1);
- load_sql_file("${STAGED_SCRIPTS_DIR}/raster_comments.sql", 0);
- load_sql_file("${STAGED_SCRIPTS_DIR}/rtpostgis_proc_set_search_path.sql", 0);
+ load_sql_file("${scriptdir}/rtpostgis.sql", 1);
+ load_sql_file("${scriptdir}/raster_comments.sql", 0);
}
if ( $OPT_WITH_SFCGAL )
{
print "Loading SFCGAL into '${DB}'\n";
- load_sql_file("${STAGED_SCRIPTS_DIR}/sfcgal.sql", 1);
- load_sql_file("${STAGED_SCRIPTS_DIR}/sfcgal_comments.sql", 0);
+ load_sql_file("${scriptdir}/sfcgal.sql", 1);
+ load_sql_file("${scriptdir}/sfcgal_comments.sql", 0);
}
return 1;
}
+sub package_extension_sql
+{
+ my ($extname, $extver) = @_;
+ my $sql;
+
+ if ( $pgvernum lt 130000 ) {
+ $sql = "CREATE EXTENSION ${extname} VERSION '${extver}' FROM unpackaged;";
+ } else {
+ $sql = "CREATE EXTENSION ${extname} VERSION unpackaged;";
+ $sql .= "ALTER EXTENSION ${extname} UPDATE TO '${extver}'";
+ }
+ return $sql;
+}
+
# Upgrade an existing database (soft upgrade)
sub upgrade_spatial
{
print "Upgrading PostGIS in '${DB}' \n" ;
- my $script = `ls ${STAGED_SCRIPTS_DIR}/postgis_upgrade.sql`;
- chomp($script);
-
- if ( -e $script )
- {
- print "Upgrading core\n";
- load_sql_file($script);
- }
- else
- {
- die "$script not found\n";
- }
+ my $script = "${STAGED_SCRIPTS_DIR}/postgis_upgrade.sql";
+ print "Upgrading core\n";
+ die unless load_sql_file($script, 1);
if ( $OPT_WITH_TOPO )
{
- my $script = `ls ${STAGED_SCRIPTS_DIR}/topology_upgrade.sql`;
- chomp($script);
- if ( -e $script )
- {
- print "Upgrading topology\n";
- load_sql_file($script);
- }
- else
- {
- die "$script not found\n";
- }
+ $script = "${STAGED_SCRIPTS_DIR}/topology_upgrade.sql";
+ print "Upgrading topology\n";
+ die unless load_sql_file($script, 1);
}
if ( $OPT_WITH_RASTER )
{
- my $script = `ls ${STAGED_SCRIPTS_DIR}/rtpostgis_upgrade.sql`;
- chomp($script);
- if ( -e $script )
- {
- print "Upgrading raster\n";
- load_sql_file($script);
- }
- else
- {
- die "$script not found\n";
- }
+ $script = "${STAGED_SCRIPTS_DIR}/rtpostgis_upgrade.sql";
+ print "Upgrading raster\n";
+ die unless load_sql_file($script, 1);
}
if ( $OPT_WITH_SFCGAL )
{
- my $script = `ls ${STAGED_SCRIPTS_DIR}/sfcgal_upgrade.sql`;
- chomp($script);
- if ( -e $script )
- {
- print "Upgrading sfcgal\n";
- load_sql_file($script);
- }
- else
- {
- die "$script not found\n";
- }
+ $script = "${STAGED_SCRIPTS_DIR}/sfcgal_upgrade.sql";
+ print "Upgrading sfcgal\n";
+ die unless load_sql_file($script, 1);
}
return 1;
@@ -1463,11 +1613,44 @@ sub upgrade_spatial_extensions
{
# 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 =~ /!$/ )
+ {
+ $OPT_UPGRADE_TO =~ s/!$//;
+ my $from = $OPT_UPGRADE_FROM;
+ $from =~ s/^unpackaged//;
+ if ( ! $from || ! semver_lessthan($from, "3.0.0") )
+ {
+ $upgrade_via_function = 1;
+ }
+ else
+ {
+ print "WARNING: postgis_extensions_upgrade()".
+ " not available or functional in version $from.".
+ " We'll use manual upgrade.\n";
+ }
+ }
+
+ if ( $OPT_UPGRADE_TO =~ /^:auto/ )
+ {
+ $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 eq "unpackaged" ) {
- $sql = "CREATE EXTENSION postgis VERSION '${nextver}' FROM unpackaged";
+ if ( $upgrade_via_function )
+ {
+ $sql = "SELECT postgis_extensions_upgrade()";
+ }
+ elsif ( $OPT_UPGRADE_FROM =~ /^unpackaged/ )
+ {
+ $sql = package_extension_sql('postgis', ${nextver});
+ }
+ else
+ {
+ $sql = "ALTER EXTENSION postgis UPDATE TO '${nextver}'";
}
print "Upgrading PostGIS in '${DB}' using: ${sql}\n" ;
@@ -1476,24 +1659,95 @@ sub upgrade_spatial_extensions
#print "CMD: " . $cmd . "\n";
my $rv = system($cmd);
if ( $rv ) {
- fail "Error encountered altering EXTENSION POSTGIS", $REGRESS_LOG;
+ fail "Error encountered updating EXTENSION POSTGIS", $REGRESS_LOG;
die;
}
+ # Handle raster split if coming from pre-split and going
+ # to splitted raster
+ if ( $OPT_UPGRADE_FROM && has_split_raster_ext($OPT_UPGRADE_TO) &&
+ ! has_split_raster_ext($OPT_UPGRADE_FROM) )
+ {
+ if ( $OPT_WITH_RASTER )
+ {
+ # upgrade of postgis must have unpackaged raster, so
+ # we create it again here
+ my $sql = package_extension_sql('postgis_raster', ${nextver});
+
+ print "Upgrading PostGIS Raster 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 creating EXTENSION POSTGIS_RASTER from unpackaged on upgrade", $REGRESS_LOG;
+ die;
+ }
+ }
+ else
+ {
+ # Raster support was not requested, so drop it if
+ # left unpackaged
+ print "Packaging PostGIS Raster in '${DB}' for later drop using: ${sql}\n" ;
+
+ $sql = package_extension_sql('postgis_raster', ${nextver});
+
+ $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+ $rv = system($cmd);
+ if ( $rv ) {
+ fail "Error encountered creating EXTENSION POSTGIS_RASTER from unpackaged on upgrade", $REGRESS_LOG;
+ die;
+ }
+
+ print "Dropping PostGIS Raster in '${DB}' using: ${sql}\n" ;
+
+ $sql = "DROP EXTENSION postgis_raster";
+ $cmd = "psql $psql_opts -c \"" . $sql . "\" $DB >> $REGRESS_LOG 2>&1";
+ $rv = system($cmd);
+ if ( $rv ) {
+ fail "Error encountered dropping EXTENSION POSTGIS_RASTER on upgrade", $REGRESS_LOG;
+ die;
+ }
+ }
+ }
+
+ if ( $upgrade_via_function )
+ {
+ # The function does everything
+ return 1;
+ }
+
+ if ( $OPT_WITH_RASTER )
+ {
+ my $sql = "ALTER EXTENSION postgis_raster UPDATE TO '${nextver}'";
+
+ if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+ $sql = package_extension_sql('postgis_raster', ${nextver});
+ }
+
+ print "Upgrading PostGIS Raster 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_RASTER", $REGRESS_LOG;
+ die;
+ }
+ }
+
if ( $OPT_WITH_TOPO )
{
my $sql = "ALTER EXTENSION postgis_topology UPDATE TO '${nextver}'";
- if ( $OPT_UPGRADE_FROM eq "unpackaged" ) {
- $sql = "CREATE EXTENSION postgis_topology VERSION '${nextver}' FROM unpackaged";
+ if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+ $sql = package_extension_sql('postgis_topology', ${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 altering EXTENSION POSTGIS_TOPOLOGY", $REGRESS_LOG;
+ fail "Error encountered updating EXTENSION POSTGIS_TOPOLOGY", $REGRESS_LOG;
die;
}
}
@@ -1502,8 +1756,8 @@ sub upgrade_spatial_extensions
{
my $sql;
- if ( $OPT_UPGRADE_FROM eq "unpackaged" ) {
- $sql = "CREATE EXTENSION postgis_sfcgal VERSION '${nextver}' FROM unpackaged";
+ if ( $OPT_UPGRADE_FROM =~ /^unpackaged/ ) {
+ $sql = package_extension_sql('postgis_sfcgal', ${nextver});
}
elsif ( $OPT_UPGRADE_FROM && semver_lessthan($OPT_UPGRADE_FROM, "2.2.0") )
{
@@ -1574,10 +1828,29 @@ sub drop_spatial_extensions
$ok = 0 if $rv;
}
+ if ( $OPT_WITH_RASTER )
+ {
+ $cmd = "psql $psql_opts -c \"DROP EXTENSION IF EXISTS postgis_raster;\" $DB >> $REGRESS_LOG 2>&1";
+ $rv = system($cmd);
+ $ok = 0 if $rv;
+ }
+ if ( $OPT_WITH_TIGER )
+ {
+ $cmd = "psql $psql_opts -c \"DROP EXTENSION IF EXISTS postgis_tiger_geocoder;
+ DROP EXTENSION IF EXISTS fuzzystrmatch;
+ DROP SCHEMA IF EXISTS tiger;
+ DROP SCHEMA IF EXISTS tiger_data;
+ \" $DB >> $REGRESS_LOG 2>&1";
+ $rv = system($cmd);
+ $ok = 0 if $rv;
+ }
+
$cmd = "psql $psql_opts -c \"DROP EXTENSION postgis\" $DB >> $REGRESS_LOG 2>&1";
$rv = system($cmd);
- die "\nError encountered dropping EXTENSION POSTGIS, see $REGRESS_LOG for details\n\n"
- if $rv;
+ if ( $rv ) {
+ fail "Error encountered dropping EXTENSION POSTGIS", $REGRESS_LOG;
+ die;
+ }
return $ok;
}
@@ -1586,6 +1859,7 @@ sub drop_spatial_extensions
sub uninstall_spatial
{
my $ok;
+
start_test("uninstall");
if ( $OPT_EXTENSIONS )
@@ -1597,24 +1871,19 @@ sub uninstall_spatial
$ok = drop_spatial();
}
- if ( $ok )
- {
- show_progress(); # on to objects count
- $OBJ_COUNT_POST = count_db_objects();
+ return $ok if ! $ok;
- if ( $OBJ_COUNT_POST != $OBJ_COUNT_PRE )
- {
- fail("Object count pre-install ($OBJ_COUNT_PRE) != post-uninstall ($OBJ_COUNT_POST)");
- return 0;
- }
- else
- {
- pass("($OBJ_COUNT_PRE)");
- return 1;
- }
+ show_progress(); # on to objects count
+ $OBJ_COUNT_POST = count_db_objects();
+
+ if ( $OBJ_COUNT_POST != $OBJ_COUNT_PRE )
+ {
+ fail("Object count pre-install ($OBJ_COUNT_PRE) != post-uninstall ($OBJ_COUNT_POST)");
+ return 0;
}
- return 0;
+ pass("($OBJ_COUNT_PRE)");
+ return 1;
}
# Dump and restore the database
-----------------------------------------------------------------------
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list