From: Paul Ramsey Date: Fri, 13 Nov 2009 20:04:37 +0000 (+0000) Subject: First baby steps towards version-specific loader X-Git-Tag: 1.5.0b1~251 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0c974e159ec7e6681cc50f947264099c36e765c;p=postgis First baby steps towards version-specific loader git-svn-id: http://svn.osgeo.org/postgis/trunk@4803 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c index 9c3ed5c0e..f470078f3 100644 --- a/postgis/postgis.sql.in.c +++ b/postgis/postgis.sql.in.c @@ -21,6 +21,8 @@ #include "sqldefines.h" +-- INSTALL VERSION: POSTGIS_LIB_VERSION + BEGIN; ------------------------------------------------------------------- diff --git a/postgis/sqldefines.h.in b/postgis/sqldefines.h.in index 2dc1f5cf0..4cad91d5d 100644 --- a/postgis/sqldefines.h.in +++ b/postgis/sqldefines.h.in @@ -7,6 +7,7 @@ #define POSTGIS_PGSQL_VERSION @POSTGIS_PGSQL_VERSION@ #define POSTGIS_GEOS_VERSION @POSTGIS_GEOS_VERSION@ #define POSTGIS_PROJ_VERSION @POSTGIS_PROJ_VERSION@ +#define POSTGIS_LIB_VERSION @POSTGIS_LIB_VERSION@ /* * Define the build date and the version number diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl index c38ffbfc4..eb6961179 100755 --- a/utils/postgis_proc_upgrade.pl +++ b/utils/postgis_proc_upgrade.pl @@ -3,7 +3,7 @@ # # This script produces an .sql file containing # CREATE OR REPLACE calls for each function -# in lwpostgis.sql +# in postgis.sql # # In addition, the transaction contains # a check for Major postgis_lib_version() @@ -32,25 +32,18 @@ print "BEGIN;\n"; print "SET search_path TO $ARGV[1];\n" if @ARGV>1; open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n"; - -FUNC: while() { # # Since 1.1.0 scripts/lib/release versions are the same # - if (m/^create or replace function postgis_scripts_installed()/i) + if (/INSTALL VERSION: (.*)/) { - while() - { - if ( m/SELECT .'(\d\.\d\..*).'::text/i ) - { $NEWVERSION = $1; - last FUNC; - } - } + last; } } +close(INPUT); print "-- $NEWVERSION\n"; @@ -60,7 +53,6 @@ while() print; } -close(INPUT); open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n"; while() @@ -81,24 +73,30 @@ while() } } - if (m/^create type (\S+)/i) + if ( m/^create type (\S+)/i ) { my $newtype = $1; - print $_ if $newtypes{$newtype}; + my $def .= $_; while() { - print $_ if $newtypes{$newtype}; + $def .= $_; last if m/\)/; } + print $def if $newtypes{$newtype}; } + # 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; + } # This code handles aggregates by dropping and recreating them. - # The DROP would fail on aggregates as they would not exist - # in old postgis installations, thus we avoid this until we - # find a better strategy. - - if (/^create aggregate\s+(\S+)\s*\(/i) + if ( /^create aggregate\s+(\S+)\s*\(/i ) { my $aggname = $1; my $basetype = 'unknown'; @@ -110,9 +108,42 @@ while() last if m/\);/; } print "DROP AGGREGATE IF EXISTS $aggname($basetype);\n"; - print "$def"; + 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() + { + $def .= $_; + $basetype = $1 if ( m/leftarg\s*=\s*(\w+)\s*,/i ); + last if m/\);/; + } + print $def; } + # 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() + { + $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; + } } close( INPUT );