2005-06-06 16:49:41 +00:00
|
|
|
#/bin/sh
|
|
|
|
|
2005-12-16 08:33:04 +00:00
|
|
|
#
|
|
|
|
# This script produces an .sql file containing
|
|
|
|
# CREATE OR REPLACE calls for each function
|
2009-11-13 20:04:37 +00:00
|
|
|
# in postgis.sql
|
2005-12-16 08:33:04 +00:00
|
|
|
#
|
|
|
|
# In addition, the transaction contains
|
|
|
|
# a check for Major postgis_lib_version()
|
|
|
|
# to match the one contained in lwpostgis.sql
|
|
|
|
#
|
|
|
|
# This never happens by just running make install
|
|
|
|
# as MODULE_FILENAME contains SO_MAJOR under
|
|
|
|
# all architectures.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2005-06-06 16:49:41 +00:00
|
|
|
eval "exec perl -w $0 $@"
|
|
|
|
if (0);
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2005-10-26 11:07:55 +00:00
|
|
|
($#ARGV == 0) ||
|
2005-12-16 01:41:44 +00:00
|
|
|
die "Usage: perl postgis_proc_upgrade.pl <postgis.sql> [<schema>]\nCreates a new SQL script to upgrade all of the PostGIS functions.\n"
|
2005-10-26 11:07:55 +00:00
|
|
|
if ( @ARGV < 1 || @ARGV > 2 );
|
2005-06-06 16:49:41 +00:00
|
|
|
|
|
|
|
my $NEWVERSION = "UNDEF";
|
2009-06-08 23:21:55 +00:00
|
|
|
my %newtypes = ( "box3d_extent", 1, "pgis_abs", 1 );
|
2005-06-06 16:49:41 +00:00
|
|
|
|
|
|
|
print "BEGIN;\n";
|
|
|
|
|
2005-10-26 11:07:55 +00:00
|
|
|
print "SET search_path TO $ARGV[1];\n" if @ARGV>1;
|
|
|
|
|
2005-06-06 16:49:41 +00:00
|
|
|
open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n";
|
|
|
|
while(<INPUT>)
|
|
|
|
{
|
2005-12-16 01:41:44 +00:00
|
|
|
#
|
|
|
|
# Since 1.1.0 scripts/lib/release versions are the same
|
|
|
|
#
|
2009-11-13 20:04:37 +00:00
|
|
|
if (/INSTALL VERSION: (.*)/)
|
2005-06-06 16:49:41 +00:00
|
|
|
{
|
|
|
|
$NEWVERSION = $1;
|
2009-11-13 20:04:37 +00:00
|
|
|
last;
|
2005-06-06 16:49:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-13 20:04:37 +00:00
|
|
|
close(INPUT);
|
2005-06-06 16:49:41 +00:00
|
|
|
|
2009-06-08 23:21:55 +00:00
|
|
|
print "-- $NEWVERSION\n";
|
|
|
|
|
2005-06-06 16:49:41 +00:00
|
|
|
while(<DATA>)
|
|
|
|
{
|
|
|
|
s/NEWVERSION/$NEWVERSION/g;
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
|
2009-06-08 23:21:55 +00:00
|
|
|
|
|
|
|
open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n";
|
2005-06-06 16:49:41 +00:00
|
|
|
while(<INPUT>)
|
|
|
|
{
|
|
|
|
my $checkit = 0;
|
|
|
|
if (m/^create or replace function/i)
|
|
|
|
{
|
|
|
|
$checkit = 1 if m/postgis_scripts_installed()/i;
|
|
|
|
print $_;
|
|
|
|
while(<INPUT>)
|
|
|
|
{
|
|
|
|
if ( $checkit && m/SELECT .'(\d\.\d\.\d).'::text/i )
|
|
|
|
{
|
|
|
|
$NEWVERSION = $1;
|
|
|
|
}
|
|
|
|
print $_;
|
|
|
|
last if m/^\s*LANGUAGE '/;
|
|
|
|
}
|
|
|
|
}
|
2005-06-10 16:27:19 +00:00
|
|
|
|
2009-11-13 20:04:37 +00:00
|
|
|
if ( m/^create type (\S+)/i )
|
2009-06-08 23:21:55 +00:00
|
|
|
{
|
|
|
|
my $newtype = $1;
|
2009-11-13 20:04:37 +00:00
|
|
|
my $def .= $_;
|
2009-06-08 23:21:55 +00:00
|
|
|
while(<INPUT>)
|
|
|
|
{
|
2009-11-13 20:04:37 +00:00
|
|
|
$def .= $_;
|
2009-06-08 23:21:55 +00:00
|
|
|
last if m/\)/;
|
|
|
|
}
|
2009-11-13 20:04:37 +00:00
|
|
|
print $def if $newtypes{$newtype};
|
2009-06-08 23:21:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-13 20:04:37 +00:00
|
|
|
# This code handles casts by dropping and recreating them.
|
|
|
|
if ( /^create cast\s+\(\s*(\w+)\s+as\s+(\w+)\)/i )
|
|
|
|
{
|
|
|
|
my $type1 = $1;
|
|
|
|
my $type2 = $2;
|
|
|
|
my $def = $_;
|
|
|
|
print "DROP CAST IF EXISTS ($type1 AS $type2);\n";
|
|
|
|
print $def;
|
|
|
|
}
|
2009-06-08 23:21:55 +00:00
|
|
|
|
2009-06-03 23:56:23 +00:00
|
|
|
# This code handles aggregates by dropping and recreating them.
|
2009-11-13 20:04:37 +00:00
|
|
|
if ( /^create aggregate\s+(\S+)\s*\(/i )
|
2009-06-03 23:56:23 +00:00
|
|
|
{
|
|
|
|
my $aggname = $1;
|
|
|
|
my $basetype = 'unknown';
|
|
|
|
my $def = $_;
|
|
|
|
while(<INPUT>)
|
|
|
|
{
|
|
|
|
$def .= $_;
|
2009-06-09 22:51:14 +00:00
|
|
|
$basetype = $1 if (m/basetype\s*=\s*([^,]*)\s*,/i);
|
2009-06-03 23:56:23 +00:00
|
|
|
last if m/\);/;
|
|
|
|
}
|
|
|
|
print "DROP AGGREGATE IF EXISTS $aggname($basetype);\n";
|
2009-11-13 20:04:37 +00:00
|
|
|
print $def;
|
|
|
|
}
|
|
|
|
|
|
|
|
# This code handles operators by creating them if we are doing a major upgrade
|
|
|
|
if ( /^create operator\s+(\S+)\s*\(/i )
|
|
|
|
{
|
|
|
|
my $opname = $1;
|
|
|
|
my $basetype = 'unknown';
|
|
|
|
my $def = $_;
|
|
|
|
while(<INPUT>)
|
|
|
|
{
|
|
|
|
$def .= $_;
|
|
|
|
$basetype = $1 if ( m/leftarg\s*=\s*(\w+)\s*,/i );
|
|
|
|
last if m/\);/;
|
|
|
|
}
|
|
|
|
print $def;
|
2009-06-03 23:56:23 +00:00
|
|
|
}
|
2005-06-10 16:27:19 +00:00
|
|
|
|
2009-11-13 20:04:37 +00:00
|
|
|
# This code handles operator classes by creating them if we are doing a major upgrade
|
|
|
|
if ( /^create operator class\s+(\w+)\s*/i )
|
|
|
|
{
|
|
|
|
my $opclassname = $1;
|
|
|
|
my $opctype = 'unknown';
|
|
|
|
my $opcidx = 'unknown';
|
|
|
|
my $def = $_;
|
|
|
|
while(<INPUT>)
|
|
|
|
{
|
|
|
|
$def .= $_;
|
|
|
|
$opctype = $1 if ( m/for type (\w+) /i );
|
|
|
|
$opcidx = $1 if ( m/using (\w+) /i );
|
|
|
|
last if m/\);/;
|
|
|
|
}
|
|
|
|
$opctype =~ tr/A-Z/a-z/;
|
|
|
|
$opcidx =~ tr/A-Z/a-z/;
|
|
|
|
print $def;
|
|
|
|
}
|
2005-06-06 16:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close( INPUT );
|
|
|
|
|
|
|
|
print "COMMIT;\n";
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
2005-12-16 01:41:44 +00:00
|
|
|
CREATE OR REPLACE FUNCTION postgis_major_version_check()
|
2005-06-06 16:49:41 +00:00
|
|
|
RETURNS text
|
|
|
|
AS '
|
|
|
|
DECLARE
|
|
|
|
old_scripts text;
|
|
|
|
new_scripts text;
|
2005-12-16 08:33:04 +00:00
|
|
|
old_maj text;
|
|
|
|
new_maj text;
|
2005-06-06 16:49:41 +00:00
|
|
|
BEGIN
|
2005-12-16 01:48:52 +00:00
|
|
|
--
|
|
|
|
-- This uses postgis_lib_version() rather then
|
|
|
|
-- postgis_scripts_installed() as in 1.0 because
|
|
|
|
-- in the 1.0 => 1.1 transition that would result
|
|
|
|
-- in an impossible upgrade:
|
|
|
|
--
|
|
|
|
-- from 0.3.0 to 1.1.0
|
|
|
|
--
|
|
|
|
-- Next releases will still be ok as
|
|
|
|
-- postgis_lib_version() and postgis_scripts_installed()
|
|
|
|
-- would both return actual PostGIS release number.
|
|
|
|
--
|
2005-12-16 01:41:44 +00:00
|
|
|
SELECT into old_scripts postgis_lib_version();
|
2005-06-06 16:49:41 +00:00
|
|
|
SELECT into new_scripts ''NEWVERSION'';
|
2005-12-16 08:33:04 +00:00
|
|
|
SELECT into old_maj substring(old_scripts from 1 for 2);
|
|
|
|
SELECT into new_maj substring(new_scripts from 1 for 2);
|
2005-06-06 16:49:41 +00:00
|
|
|
|
2005-12-16 08:33:04 +00:00
|
|
|
IF old_maj != new_maj THEN
|
2009-07-08 00:20:48 +00:00
|
|
|
RAISE EXCEPTION ''Upgrade from version % to version % requires a dump/reload. See PostGIS manual for instructions'', old_scripts, new_scripts;
|
2005-06-06 16:49:41 +00:00
|
|
|
ELSE
|
|
|
|
RETURN ''Scripts versions checked for upgrade: ok'';
|
|
|
|
END IF;
|
|
|
|
END
|
|
|
|
'
|
|
|
|
LANGUAGE 'plpgsql';
|
|
|
|
|
2005-12-16 01:41:44 +00:00
|
|
|
SELECT postgis_major_version_check();
|
2005-06-06 16:49:41 +00:00
|
|
|
|
2005-12-16 01:41:44 +00:00
|
|
|
DROP FUNCTION postgis_major_version_check();
|