OpenPKG CVS Repository
  http://cvs.openpkg.org/
  ____________________________________________________________________________

  Server: cvs.openpkg.org                  Name:   Thomas Lotterer
  Root:   /v/openpkg/cvs                   Email:  [EMAIL PROTECTED]
  Module: openpkg-registry                 Date:   03-Aug-2006 01:16:14
  Branch: HEAD                             Handle: 2006080300161400

  Modified files:
    openpkg-registry        registry-db.pl

  Log:
    add erase command

  Summary:
    Revision    Changes     Path
    1.43        +35 -2      openpkg-registry/registry-db.pl
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-registry/registry-db.pl
  ============================================================================
  $ cvs diff -u -r1.42 -r1.43 registry-db.pl
  --- openpkg-registry/registry-db.pl   2 Aug 2006 23:15:34 -0000       1.42
  +++ openpkg-registry/registry-db.pl   2 Aug 2006 23:16:14 -0000       1.43
  @@ -106,6 +106,7 @@
            -V|version  print version
           Available commands:
            setup       setup/upgrade database
  +         erase       erase all data from database
       };
       $txt =~ s/^\n//s; $txt =~ s/^[ ]{8}//mg; $txt =~ s/ *$//mg;
       if ($level eq "INFO") {
  @@ -129,7 +130,8 @@
   ( $#ARGV == 0 ) || &usage("ERROR");
   
   #   check data prefix
  -if (   $ARGV[0] eq "setup") {
  +if (   $ARGV[0] eq "setup" 
  +    or $ARGV[0] eq "erase") {
       &error("required data prefix empty") if ($opt->{prefix} eq "");
       &error("required data prefix unset") if ($opt->{prefix} =~ m/[EMAIL 
PROTECTED]@$/);
   }
  @@ -154,6 +156,9 @@
   if    ($ARGV[0] eq "setup") {
       &setup();
   }
  +elsif ($ARGV[0] eq "erase") {
  +    &erase();
  +}
   exit(0);
   
   sub dbopen($)
  @@ -248,6 +253,27 @@
       return 1;
   }
   
  +sub erase ()
  +{
  +    $dbh = &dbopen("template1");
  +    die "ERROR:$0: DataBase error: ".$DBI::errstr."\n" if (not defined $dbh);
  +
  +    $sql = sprintf "DROP DATABASE %s;",
  +        $cfg->{db}->{registry}->{database};
  +    &dbdo($dbh, $sql,
  +        'database .* does not exist') || die;
  +
  +    $sql = sprintf "DROP TABLESPACE %s;",
  +        $cfg->{db}->{registry}->{tablespace};
  +    &dbdo($dbh, $sql,
  +        'tablespace .* does not exist') || die;
  +
  +    $sql = sprintf "DROP USER %s;",
  +        $cfg->{db}->{registry}->{username};
  +    &dbdo($dbh, $sql,
  +        '(user|role) .* does not exist') || die;
  +}
  +
   sub setup ()
   {
       #   create user, tablespace and database
  @@ -855,11 +881,12 @@
            [I<-D|debug>] [I<-H|help>] [I<-V|version>]
           Available commands:
            setup       setup/upgrade database
  +         erase       erase all data from database
   
   =head1 DESCRIPTION
   
   B<registry-db> is the DataBase utility for OpenPKG Registry Servers.
  -It is used by administrators to setup the
  +It is used by administrators to setup and erase the
   Registry Server and to review the default configuration, the contents
   of the used configuration file and the internal result of both being
   merged.
  @@ -908,6 +935,12 @@
   DataBase. This is an ideal precondition to start from scratch or running
   a restore.
   
  +=item B<erase>
  +
  +Erases the DataBase, destroying data, tables, database, role and
  +tablespace. NO QUESTIONS ASKED! Ideal precondition to get rid of a
  +Registry Server or restart a setup from scratch.
  +
   =back
   
   =head1 FILES
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     openpkg-cvs@openpkg.org

Reply via email to