diff options
Diffstat (limited to 'perl')
| -rw-r--r-- | perl/Wallet/Admin.pm | 29 | ||||
| -rw-r--r-- | perl/Wallet/Schema.pm | 2 | ||||
| -rwxr-xr-x | perl/t/admin.t | 7 | 
3 files changed, 30 insertions, 8 deletions
| diff --git a/perl/Wallet/Admin.pm b/perl/Wallet/Admin.pm index f208e13..8fb49af 100644 --- a/perl/Wallet/Admin.pm +++ b/perl/Wallet/Admin.pm @@ -1,7 +1,8 @@  # Wallet::Admin -- Wallet system administrative interface.  #  # Written by Russ Allbery <rra@stanford.edu> -# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University +# Copyright 2008, 2009, 2010, 2011 +#     The Board of Trustees of the Leland Stanford Junior University  #  # See LICENSE for licensing terms. @@ -22,7 +23,7 @@ use Wallet::Schema;  # This version should be increased on any code change to this module.  Always  # use two digits for the minor version with a leading zero if necessary so  # that it will sort properly. -$VERSION = '0.05'; +$VERSION = '0.06';  ##############################################################################  # Constructor, destructor, and accessors @@ -110,6 +111,19 @@ sub destroy {      return 1;  } +# Upgrade the database to the latest schema version.  Returns true on success +# and false on failure. +sub upgrade { +    my ($self) = @_; +    my $schema = Wallet::Schema->new; +    eval { $schema->upgrade ($self->{dbh}) }; +    if ($@) { +        $self->error ($@); +        return; +    } +    return 1; +} +  ##############################################################################  # Object registration  ############################################################################## @@ -204,12 +218,12 @@ failure to get the error message.  =over 4 -=item destroy() +=item destroy ()  Destroys the database, deleting all of its data and all of the tables used  by the wallet server.  Returns true on success and false on failure. -=item error() +=item error ()  Returns the error of the last failing operation or undef if no operations  have failed.  Callers should call this function to get the error message @@ -240,7 +254,7 @@ Register in the database a mapping from the ACL scheme SCHEME to the class  CLASS.  Returns true on success and false on failure (including when the  verifier is already registered). -=item reinitialize(PRINCIPAL) +=item reinitialize (PRINCIPAL)  Performs the same actions as initialize(), but first drops any existing  wallet database tables from the database, allowing this function to be @@ -249,6 +263,11 @@ be deleted and a fresh set of wallet database tables will be created.  This method is equivalent to calling destroy() followed by initialize().  Returns true on success and false on failure. +=item upgrade () + +Upgrades the database to the latest schema version, preserving data as +much as possible.  Returns true on success and false on failure. +  =back  =head1 SEE ALSO diff --git a/perl/Wallet/Schema.pm b/perl/Wallet/Schema.pm index 911d7a9..0f6c53f 100644 --- a/perl/Wallet/Schema.pm +++ b/perl/Wallet/Schema.pm @@ -126,7 +126,7 @@ sub _schema_version {      eval {          my $sql = 'select md_version from metadata';          my $result = $dbh->selectrow_arrayref ($sql); -        $version = $result->[0][0]; +        $version = $result->[0];      };      if ($@) {          $version = 0; diff --git a/perl/t/admin.t b/perl/t/admin.t index 074dbc6..6250f8e 100755 --- a/perl/t/admin.t +++ b/perl/t/admin.t @@ -3,11 +3,12 @@  # Tests for wallet administrative interface.  #  # Written by Russ Allbery <rra@stanford.edu> -# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University +# Copyright 2008, 2009, 2010, 2011 +#     The Board of Trustees of the Leland Stanford Junior University  #  # See LICENSE for licensing terms. -use Test::More tests => 16; +use Test::More tests => 18;  use Wallet::Admin;  use Wallet::Report; @@ -24,6 +25,8 @@ is ($@, '', 'Wallet::Admin creation did not die');  ok ($admin->isa ('Wallet::Admin'), ' and returned the right class');  is ($admin->initialize ('admin@EXAMPLE.COM'), 1,      ' and initialization succeeds'); +is ($admin->upgrade, 1, ' and upgrade succeeds (should do nothing)'); +is ($admin->error, undef, ' and there is no error');  # We have an empty database, so we should see no objects and one ACL.  my $report = Wallet::Report->new; | 
