aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorJon Robertson <jonrober@stanford.edu>2012-12-02 22:07:16 -0800
committerRuss Allbery <rra@stanford.edu>2013-01-30 18:33:23 -0800
commit593e9b1e100ace54d1d9da7eb16e60f4e37c34ff (patch)
tree6d29f76135fff795f6a15f9b379fc6dee72d14f0 /server
parent6530fb472f1c64d3e80c723d3073ca3d256a58ce (diff)
Moved the Perl wallet modules and tests to DBIx::Class
Moved all the Perl code to use DBIx::Class for the database interface. This includes updating all database calls, how the schema is generated and maintained, and the tests in places where some output has changed. We also remove the schema.t test, as the tests for it are more covered in the admin.t tests now. Change-Id: Ie5083432d09a0d9fe364a61c31378b77aa7b3cb7 Reviewed-on: https://gerrit.stanford.edu/598 Reviewed-by: Russ Allbery <rra@stanford.edu> Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'server')
-rwxr-xr-xserver/wallet-admin23
1 files changed, 23 insertions, 0 deletions
diff --git a/server/wallet-admin b/server/wallet-admin
index 94d62c7..7e5a402 100755
--- a/server/wallet-admin
+++ b/server/wallet-admin
@@ -15,6 +15,13 @@
use strict;
use Wallet::Admin;
+# The last non-DBIx::Class version. If a database has no DBIx::Class
+# versioning, we want to set it to this so that upgrades can begin.
+our $BASE_VERSION = '0.07';
+
+# Directory that contains the wallet SQL files for upgrades.
+our $SQL_DIR = '/usr/share/wallet/sql/';
+
##############################################################################
# Implementation
##############################################################################
@@ -41,6 +48,9 @@ sub command {
die "too few arguments to initialize\n" if @args < 1;
die "invalid admin principal $args[0]\n"
unless $args[0] =~ /^[^\@\s]+\@\S+$/;
+
+ my $schema = $admin->{dbh};
+ $schema->upgrade_directory ($SQL_DIR);
$admin->initialize (@args) or die $admin->error, "\n";
} elsif ($command eq 'register') {
die "too many arguments to register\n" if @args > 3;
@@ -59,7 +69,20 @@ sub command {
}
} elsif ($command eq 'upgrade') {
die "too many arguments to upgrade\n" if @args;
+
+ my $schema = $admin->{dbh};
+ $schema->upgrade_directory ($SQL_DIR);
+
+ # Check to see if the database is versioned. If not, install the
+ # versioning table and default version.
+ if (!$schema->get_db_version) {
+ print "Versioning database.\n";
+ $schema->install ($BASE_VERSION);
+ }
+
+ # Actually upgrade.
$admin->upgrade or die $admin->error, "\n";
+
} else {
die "unknown command $command\n";
}