aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2007-08-29 22:56:52 +0000
committerRuss Allbery <rra@stanford.edu>2007-08-29 22:56:52 +0000
commit007f40ddec0d0c594f82716dd64cf5b676bc1ceb (patch)
treeaa90944f6557377370b625bf0f6db89bbea50248
parente8a4e031eb1604d8a3c61baf7340c986833ec986 (diff)
Add an initialize function to Wallet::Server to set up the database.
-rw-r--r--perl/Wallet/Server.pm16
1 files changed, 16 insertions, 0 deletions
diff --git a/perl/Wallet/Server.pm b/perl/Wallet/Server.pm
index 902e86d..28be35c 100644
--- a/perl/Wallet/Server.pm
+++ b/perl/Wallet/Server.pm
@@ -72,6 +72,22 @@ sub new {
return $self;
}
+# Initializes the database by populating it with our schema. This will fail
+# if the database is already created and an administrator will have to drop
+# the tables by hand. Returns true on success and false on failure. On
+# failure, sets the internal error message.
+sub initialize {
+ my ($self) = @_;
+ my $schema = Wallet::Schema->new;
+ eval { $schema->create ($self->{dbh}) };
+ if ($@) {
+ $self->{error} = $@;
+ return undef;
+ } else {
+ return 1;
+ }
+}
+
# Returns the error from the previous failed operation.
sub error {
my ($self) = @_;