}
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";
}
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