3 # $Id: db-delete.pl,v 1.1.1.1 2004/03/29 01:20:13 vjrj Exp $
5 # Debian-specific script to delete plugin-specific tables
6 # Roland Mas <lolando@debian.org>
15 use vars qw/$dbh @reqlist $query/ ;
16 use vars qw/$sys_default_domain $sys_cvs_host
17 $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host
18 $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR
19 $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot
20 $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd
21 $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password
24 use vars qw/$pluginname/ ;
26 sub is_lesser ( $$ ) ;
27 sub is_greater ( $$ ) ;
29 sub parse_sql_file ( $ ) ;
31 require ("/usr/share/gforge/lib/include.pl") ; # Include a few predefined functions
32 require ("/usr/share/gforge/lib/sqlparser.pm") ; # Our magic SQL parser
33 require ("/usr/share/gforge/lib/sqlhelper.pm") ; # A few SQL helper functions
35 debug "You'll see some debugging info during this installation." ;
36 debug "Do not worry unless told otherwise." ;
40 # debug "Connected to the database OK." ;
42 $pluginname = "globalsearch" ;
44 $dbh->{AutoCommit} = 0;
45 $dbh->{RaiseError} = 1;
47 my ($sth, @array, $version, $action, $path, $target, $rname) ;
49 # Drop a few tables in a specific order
50 &drop_table_if_exists ($dbh, "plugin_globalsearch_assoc_site_project") ;
51 &drop_table_if_exists ($dbh, "plugin_globalsearch_assoc_site") ;
52 &drop_table_if_exists ($dbh, "plugin_globalsearch_assoc_status") ;
54 # Then drop any remaining data structures
55 my $pattern = "plugin_" . $pluginname . '_%' ;
57 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='v'" ;
58 $sth = $dbh->prepare ($query) ;
60 while (@array = $sth->fetchrow_array ()) {
62 &drop_view_if_exists ($dbh, $rname) ;
66 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='r'" ;
67 $sth = $dbh->prepare ($query) ;
69 while (@array = $sth->fetchrow_array ()) {
71 &drop_table_if_exists ($dbh, $rname) ;
75 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='i'" ;
76 $sth = $dbh->prepare ($query) ;
78 while (@array = $sth->fetchrow_array ()) {
80 &drop_index_if_exists ($dbh, $rname) ;
84 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='S'" ;
85 $sth = $dbh->prepare ($query) ;
87 while (@array = $sth->fetchrow_array ()) {
89 &drop_sequence_if_exists ($dbh, $rname) ;
96 debug "It seems your database deletion went well and smoothly. That's cool." ;
97 debug "Please enjoy using Debian GForge." ;
99 # There should be a commit at the end of every block above.
100 # If there is not, then it might be symptomatic of a problem.
101 # For safety, we roll back.
106 warn "Transaction aborted because $@" ;
107 debug "Transaction aborted because $@" ;
108 debug "Last SQL query was:\n$query\n(end of query)" ;
110 debug "Please report this bug on the Debian bug-tracking system." ;
111 debug "Please include the previous messages as well to help debugging." ;
112 debug "You should not worry too much about this," ;
113 debug "your DB is still in a consistent state and should be usable." ;