summaryrefslogtreecommitdiff
path: root/perl/Wallet
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2011-05-17 16:11:06 -0700
committerRuss Allbery <rra@stanford.edu>2011-05-17 16:11:06 -0700
commit4ee50d93cf99f55a503d0ca788e6c1a468eeacf6 (patch)
treed03149c8148c682337f791b45b76226ed613f04f /perl/Wallet
parentdeaa5c140e85d8e1248d910f0721c9e00a46e439 (diff)
Add wallet-admin upgrade command to upgrade the database
Hook the new upgrade method of Wallet::Schema into Wallet::Admin and the wallet-admin wrapper script.
Diffstat (limited to 'perl/Wallet')
-rw-r--r--perl/Wallet/Admin.pm29
-rw-r--r--perl/Wallet/Schema.pm2
2 files changed, 25 insertions, 6 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;