From 45aa7180a312e0e5bcc546f613236ded2d253768 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 12 Apr 2013 16:10:28 +0000 Subject: [PATCH] postgis_restore.pl support for dump with postgis in custom schema See #2264 -- thanks Thomas (frost242) git-svn-id: http://svn.osgeo.org/postgis/trunk@11285 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 2 ++ utils/postgis_restore.pl.in | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 6d93fa369..ba9f57b8c 100644 --- a/NEWS +++ b/NEWS @@ -80,6 +80,7 @@ PostGIS 2.1.0 - #2123, ST_FromGDALRaster * Enhancements * + - #823, tiger geocoder: Make loader_generate_script download portion less greedy - #826, raster2pgsql no longer defaults to padding tiles. Flag -P @@ -127,6 +128,7 @@ PostGIS 2.1.0 - #2202, Make libjson-c optional (--without-json configure switch) - #2231, raster2pgsql supports user naming of filename column with -n - #2200, ST_Union(raster, uniontype) unions all bands of all rasters + - #2264, postgis_restore.pl support for dump with postgis in custom schema * Fixes * diff --git a/utils/postgis_restore.pl.in b/utils/postgis_restore.pl.in index 4315c126b..be31f22c6 100755 --- a/utils/postgis_restore.pl.in +++ b/utils/postgis_restore.pl.in @@ -34,7 +34,7 @@ use strict; my $me = $0; my $usage = qq{ -Usage: $me [-v] +Usage: $me [-v] [-s schema] Restore a custom dump (pg_dump -Fc) of a PostGIS-enabled database. First dump the old database: pg_dump -Fc MYDB > MYDB.dmp Then create a new database: createdb NEWDB @@ -50,15 +50,22 @@ Usage: $me [-v] }; my $DEBUG = 0; +my $POSTGIS_SCHEMA; # NOTE: the SRID limits here are being discussed: # http://postgis.refractions.net/pipermail/postgis-devel/2012-February/018463.html my $SRID_MAXIMUM = @SRID_MAXIMUM@; my $SRID_USER_MAXIMUM = @SRID_USER_MAXIMUM@; -if ( @ARGV && $ARGV[0] eq '-v' ) { - $DEBUG = 1; - shift(@ARGV); +while (@ARGV && $ARGV[0] =~ /-/) { + if ( $ARGV[0] eq '-v' ) { + $DEBUG = 1; + shift(@ARGV); + } + elsif ( $ARGV[0] eq '-s' ) { + shift(@ARGV); + $POSTGIS_SCHEMA = shift(@ARGV); + } } die $usage if (@ARGV < 1); @@ -120,6 +127,10 @@ close(DUMP) || die "$me: pg_restore returned an error\n"; print STDERR " Writing ASCII to stdout...\n"; open( INPUT, "pg_restore -L $manifest $dumpfile |") || die "$me:\tCan't run pg_restore\n"; +if ( defined $POSTGIS_SCHEMA ) { + print STDOUT "SET search_path = \"" . $POSTGIS_SCHEMA . "\";\n"; +} + # # Disable topology metadata tables triggers to allow for population # in arbitrary order. @@ -280,6 +291,10 @@ while( my $l = ) { } +if ( defined $POSTGIS_SCHEMA ) { + print STDOUT "SET search_path = \"" . $POSTGIS_SCHEMA . "\";\n"; +} + if ( $hasTopology ) { # Re-enable topology.layer table triggers -- 2.50.1