From 478edfe586211f064b5303060cdfa1dec323e93c Mon Sep 17 00:00:00 2001 From: No Body Date: Fri, 10 Jun 2005 16:27:19 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'pgis_1_0'. git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@1760 b70326c6-7e19-0410-871a-916f4a2858ee --- utils/create_undef.pl | 168 ++++++++++++++++++++++++++++++++++ utils/postgis_proc_upgrade.pl | 112 +++++++++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100755 utils/create_undef.pl create mode 100755 utils/postgis_proc_upgrade.pl diff --git a/utils/create_undef.pl b/utils/create_undef.pl new file mode 100755 index 000000000..499d258b4 --- /dev/null +++ b/utils/create_undef.pl @@ -0,0 +1,168 @@ +# perl create_undef.pl +# creates a new sql script to delete all the postgis functions et al. + +($#ARGV == 1) || die "Usage: perl create_undef.pl \nCreates a new SQL script to delete all the PostGIS functions.\n"; + +# drops are in the following order: +# 1. Indexing system stuff +# 2. Meta datatables +# 3. Aggregates +# 3. Casts +# 4. Operators +# 5. Functions +# 6. Types +# 7. Tables + +my @aggs = (); +my @casts = (); +my @funcs = (); +my @types = (); +my @ops = (); + +my $version = $ARGV[1]; + +print "BEGIN;\n"; + +if ( $version ge "73" ) +{ + print "-- Drop index bindings from system tables\n"; + print "DROP OPERATOR CLASS gist_geometry_ops USING gist CASCADE;\n"; +} +else +{ + print "-- Drop index bindings from system tables\n"; + print "DELETE FROM pg_amproc WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n"; + print "DELETE FROM pg_amop WHERE amopclaid = (SELECT oid FROM pg_opclass WHERE opcname = 'gist_geometry_ops');\n"; + print "DELETE FROM pg_opclass WHERE opcname = 'gist_geometry_ops';\n"; +} + + +open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n"; + +while( my $line = ) +{ + $line =~ s/[\r\n]//g; + push (@funcs, $line) if ($line =~ /^create function/i); + push (@funcs, $line) if ($line =~ /^create or replace function/i); + push (@ops, $line) if ($line =~ /^create operator.*\(/i); + push (@aggs, $line) if ($line =~ /^create aggregate/i); + push (@types, $line) if ($line =~ /^create type/i); + push (@casts, $line) if ($line =~ /^create cast/i); +} + +close( INPUT ); + +print "-- Drop all aggregates.\n"; + +foreach my $agg (@aggs) +{ + if ( $agg =~ /create aggregate\s*(\w+)\s*\(/i ) + { + if ( $version eq "71" ) + { + print "DROP AGGREGATE $1 geometry;\n"; + } + else + { + print "DROP AGGREGATE $1 ( geometry );\n"; + } + } + else + { + die "Couldn't parse line: $agg\n"; + } +} + +print "-- Drop all operators.\n"; + +foreach my $op (@ops) +{ + if ($op =~ /create operator ([^(]+)/i ) + { + if ( $version ge "73" ) + { + print "DROP OPERATOR $1 (geometry,geometry) CASCADE;\n"; + } + else + { + print "DROP OPERATOR $1 (geometry,geometry);\n"; + } + } + else + { + die "Couldn't parse line: $op\n"; + } +} + + +print "-- Drop all casts.\n"; + +foreach my $cast (@casts) +{ + if ($cast =~ /create cast\s*\((.+?)\)/i ) + { + print "DROP CAST ($1);\n"; + } + else + { + die "Couldn't parse line: $cast\n"; + } +} + +print "-- Drop all functions.\n"; + +foreach my $fn (@funcs) +{ + if ($fn =~ /.* function ([^(]+)\((.*)\)/i ) + { + my $fn_nm = $1; + my $fn_arg = $2; + + if ( $version ge "73" ) + { + if ( ! ( $fn_nm =~ /_in/i || $fn_nm =~ /_out/i || $fn_nm =~ /_recv/i || $fn_nm =~ /_send/i || $fn_nm =~ /_analyze/i ) ) + { + print "DROP FUNCTION $fn_nm ($fn_arg) CASCADE;\n"; + } + } + else + { + print "DROP FUNCTION $fn_nm ($fn_arg);\n"; + } + } + else + { + die "Couldn't parse line: $fn\n"; + } +} + +print "-- Drop all types.\n"; + +foreach my $type (@types) +{ + if ($type =~ /create type ([^(]+)/i ) + { + if ( $version ge "73" ) + { + print "DROP TYPE $1 CASCADE;\n"; + } + else + { + print "DROP TYPE $1;\n"; + } + } + else + { + die "Couldn't parse line: $type\n"; + } +} + +print "-- Drop all tables.\n"; +print "DROP TABLE spatial_ref_sys;\n"; +print "DROP TABLE geometry_columns;\n"; +print "\n"; + +print "COMMIT;\n"; + +1; + diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl new file mode 100755 index 000000000..eec853a1a --- /dev/null +++ b/utils/postgis_proc_upgrade.pl @@ -0,0 +1,112 @@ +#/bin/sh + +eval "exec perl -w $0 $@" + if (0); + +use strict; + +($#ARGV == 0) || die "Usage: perl postgis_funxupgrade.pl \nCreates a new SQL script to upgrade all of the PostGIS functions.\n"; + +my $NEWVERSION = "UNDEF"; + +print "BEGIN;\n"; + +open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n"; + +FUNC: +while() +{ + if (m/^create or replace function postgis_scripts_installed()/i) + { + while() + { + if ( m/SELECT .'(\d\.\d\.\d).'::text/i ) + { + $NEWVERSION = $1; + last FUNC; + } + } + } +} + +while() +{ + s/NEWVERSION/$NEWVERSION/g; + print; +} + +close(INPUT); open( INPUT, $ARGV[0] ) || die "Couldn't open file: $ARGV[0]\n"; +while() +{ + my $checkit = 0; + if (m/^create or replace function/i) + { + $checkit = 1 if m/postgis_scripts_installed()/i; + print $_; + while() + { + if ( $checkit && m/SELECT .'(\d\.\d\.\d).'::text/i ) + { + $NEWVERSION = $1; + } + print $_; + last if m/^\s*LANGUAGE '/; + } + } + +# # 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 (m/^create aggregate (.*) *\(/i) +# { +# my $aggname = $1; +# my $basetype = 'unknown'; +# my $def = $_; +# while() +# { +# $def .= $_; +# $basetype = $1 if (m/basetype *= *([^,]*) *,/); +# last if m/\);/; +# } +# print "DROP AGGREGATE $aggname($basetype);\n"; +# print "$def"; +# } + +} + +close( INPUT ); + +print "COMMIT;\n"; + +1; + +__END__ + +CREATE OR REPLACE FUNCTION postgis_script_version_check() +RETURNS text +AS ' +DECLARE + old_scripts text; + new_scripts text; + old_majmin text; + new_majmin text; +BEGIN + SELECT into old_scripts postgis_scripts_installed(); + SELECT into new_scripts ''NEWVERSION''; + SELECT into old_majmin substring(old_scripts from ''[^\.]*\.[^\.]*''); + SELECT into new_majmin substring(new_scripts from ''[^\.]*\.[^\.]*''); + + IF old_majmin != new_majmin THEN + RAISE EXCEPTION ''Scripts upgrade from version % to version % requires a dump/reload. See postgis manual for instructions'', old_scripts, new_scripts; + ELSE + RETURN ''Scripts versions checked for upgrade: ok''; + END IF; +END +' +LANGUAGE 'plpgsql'; + +SELECT postgis_script_version_check(); + +DROP FUNCTION postgis_script_version_check(); -- 2.50.0