2010-01-20 20:17:09 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2005-07-13 14:26:47 +00:00
|
|
|
eval "exec perl -w $0 $@"
|
|
|
|
if (0);
|
|
|
|
|
2001-08-08 21:54:15 +00:00
|
|
|
# perl create_undef.pl <postgis.sql>
|
|
|
|
# creates a new sql script to delete all the postgis functions et al.
|
|
|
|
|
2004-08-08 18:09:01 +00:00
|
|
|
($#ARGV == 1) || die "Usage: perl create_undef.pl <postgis.sql> <pgsql_version #>\nCreates a new SQL script to delete all the PostGIS functions.\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
|
|
|
# drops are in the following order:
|
|
|
|
# 1. Indexing system stuff
|
|
|
|
# 2. Meta datatables <not done>
|
2002-12-10 04:37:03 +00:00
|
|
|
# 3. Aggregates
|
|
|
|
# 3. Casts
|
|
|
|
# 4. Operators
|
2001-08-08 21:54:15 +00:00
|
|
|
# 5. Functions
|
|
|
|
# 6. Types
|
2001-10-18 16:39:44 +00:00
|
|
|
# 7. Tables
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
my @aggs = ();
|
|
|
|
my @casts = ();
|
|
|
|
my @funcs = ();
|
|
|
|
my @types = ();
|
|
|
|
my @ops = ();
|
|
|
|
|
|
|
|
my $version = $ARGV[1];
|
|
|
|
|
|
|
|
print "BEGIN;\n";
|
|
|
|
|
2004-06-03 13:44:30 +00:00
|
|
|
if ( $version ge "73" )
|
2002-12-10 04:37:03 +00:00
|
|
|
{
|
|
|
|
print "-- Drop index bindings from system tables\n";
|
2004-06-03 13:44:30 +00:00
|
|
|
print "DROP OPERATOR CLASS gist_geometry_ops USING gist CASCADE;\n";
|
2002-12-10 04:37:03 +00:00
|
|
|
}
|
|
|
|
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 = <INPUT>)
|
|
|
|
{
|
|
|
|
$line =~ s/[\r\n]//g;
|
|
|
|
push (@funcs, $line) if ($line =~ /^create function/i);
|
2004-06-03 13:44:30 +00:00
|
|
|
push (@funcs, $line) if ($line =~ /^create or replace function/i);
|
2002-12-10 04:37:03 +00:00
|
|
|
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);
|
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
close( INPUT );
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all aggregates.\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
foreach my $agg (@aggs)
|
|
|
|
{
|
|
|
|
if ( $agg =~ /create aggregate\s*(\w+)\s*\(/i )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
if ( $version eq "71" )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP AGGREGATE $1 geometry;\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
else
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP AGGREGATE $1 ( geometry );\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
else
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
die "Couldn't parse line: $agg\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all operators.\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
foreach my $op (@ops)
|
|
|
|
{
|
|
|
|
if ($op =~ /create operator ([^(]+)/i )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2004-06-03 13:44:30 +00:00
|
|
|
if ( $version ge "73" )
|
|
|
|
{
|
|
|
|
print "DROP OPERATOR $1 (geometry,geometry) CASCADE;\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "DROP OPERATOR $1 (geometry,geometry);\n";
|
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Couldn't parse line: $op\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all casts.\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
foreach my $cast (@casts)
|
|
|
|
{
|
|
|
|
if ($cast =~ /create cast\s*\((.+?)\)/i )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP CAST ($1);\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Couldn't parse line: $cast\n";
|
|
|
|
}
|
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all functions.\n";
|
|
|
|
|
|
|
|
foreach my $fn (@funcs)
|
|
|
|
{
|
2004-06-14 08:06:13 +00:00
|
|
|
if ($fn =~ /.* function ([^(]+)\((.*)\)/i )
|
2002-12-10 04:37:03 +00:00
|
|
|
{
|
|
|
|
my $fn_nm = $1;
|
|
|
|
my $fn_arg = $2;
|
2004-06-14 08:06:13 +00:00
|
|
|
|
2004-06-03 13:44:30 +00:00
|
|
|
if ( $version ge "73" )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2004-06-03 13:44:30 +00:00
|
|
|
if ( ! ( $fn_nm =~ /_in/i || $fn_nm =~ /_out/i || $fn_nm =~ /_recv/i || $fn_nm =~ /_send/i || $fn_nm =~ /_analyze/i ) )
|
2002-12-10 04:37:03 +00:00
|
|
|
{
|
2004-06-03 13:44:30 +00:00
|
|
|
print "DROP FUNCTION $fn_nm ($fn_arg) CASCADE;\n";
|
2002-12-10 04:37:03 +00:00
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP FUNCTION $fn_nm ($fn_arg);\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Couldn't parse line: $fn\n";
|
|
|
|
}
|
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all types.\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
foreach my $type (@types)
|
|
|
|
{
|
2005-07-13 14:26:47 +00:00
|
|
|
if ($type =~ /create type (\w+)/i )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2004-06-03 13:44:30 +00:00
|
|
|
if ( $version ge "73" )
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP TYPE $1 CASCADE;\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
else
|
2001-08-08 21:54:15 +00:00
|
|
|
{
|
2002-12-10 04:37:03 +00:00
|
|
|
print "DROP TYPE $1;\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-10 04:37:03 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
die "Couldn't parse line: $type\n";
|
|
|
|
}
|
|
|
|
}
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "-- Drop all tables.\n";
|
|
|
|
print "DROP TABLE spatial_ref_sys;\n";
|
|
|
|
print "DROP TABLE geometry_columns;\n";
|
|
|
|
print "\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
2002-12-10 04:37:03 +00:00
|
|
|
print "COMMIT;\n";
|
2001-08-08 21:54:15 +00:00
|
|
|
|
|
|
|
1;
|
|
|
|
|