]> granicus.if.org Git - postgis/commitdiff
Strip schemas from search_path as part of uninstall procedures
authorSandro Santilli <strk@keybit.net>
Wed, 28 Mar 2012 14:02:31 +0000 (14:02 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 28 Mar 2012 14:02:31 +0000 (14:02 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9570 b70326c6-7e19-0410-871a-916f4a2858ee

utils/create_undef.pl

index 21c189b24158d253d4d50a3dd3a20e781654c869..80232dd629337a399c898c614728224b0ff5f0c9 100755 (executable)
@@ -269,9 +269,15 @@ foreach my $fn (@type_funcs)
 }
 
 print "-- Drop all schemas.\n";
-foreach my $schema (@schemas)
+if (@schemas)
 {
-       print "DROP SCHEMA $schema;\n";
+  print <DATA>;
+  foreach my $schema (@schemas)
+  {
+    print "SELECT undef_helper.StripFromSearchPath('$schema');\n";
+    print "DROP SCHEMA \"$schema\";\n";
+  }
+  print "DROP SCHEMA undef_helper CASCADE;\n";
 }
 
 
@@ -281,3 +287,39 @@ print "COMMIT;\n";
 
 1;
 
+__END__
+create schema undef_helper;
+--{
+--  StripFromSearchPath(schema_name)
+--
+-- Strips the specified schema from the database search path
+-- 
+-- This is a helper function for uninstall
+-- We may want to move this function as a generic helper
+--
+CREATE OR REPLACE FUNCTION undef_helper.StripFromSearchPath(a_schema_name varchar)
+RETURNS text
+AS
+$$
+DECLARE
+       var_result text;
+       var_search_path text;
+BEGIN
+       SELECT reset_val INTO var_search_path FROM pg_settings WHERE name = 'search_path';
+       IF var_search_path NOT LIKE '%' || quote_ident(a_schema_name) || '%' THEN
+               var_result := a_schema_name || ' not in database search_path';
+       ELSE
+    var_search_path := btrim( regexp_replace(
+        replace(var_search_path, a_schema_name, ''), ', *,', ','),
+        ', ');
+    RAISE NOTICE 'New search_path: %', var_search_path;
+               EXECUTE 'ALTER DATABASE ' || quote_ident(current_database()) || ' SET search_path = ' || var_search_path;
+               var_result := a_schema_name || ' has been stripped off database search_path ';
+       END IF;
+  
+  RETURN var_result;
+END
+$$
+LANGUAGE 'plpgsql' VOLATILE STRICT;
+
+--} StripFromSearchPath