From: Luke Reeves Date: Sun, 12 Jul 2009 15:08:37 +0000 (-0400) Subject: Corrected database schema upgrading X-Git-Tag: 2.1-alpha-2019-0-29~155 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=326c670fafa45d6a2b6c1244cad98a61addec893;p=insipid.git Corrected database schema upgrading --- diff --git a/lib/Insipid/Database.pm b/lib/Insipid/Database.pm index bfbd336..11278da 100755 --- a/lib/Insipid/Database.pm +++ b/lib/Insipid/Database.pm @@ -55,10 +55,6 @@ $dbh = DBI->connect($dsn, $dbuser, $dbpass, { 'RaiseError' => 0}) or die $DBI::e my %options; -#if(need_upgrade() eq 1) { -# dbupgrade(); -#} - sub export_options { my ($writer) = (@_); my ($sth); @@ -107,34 +103,33 @@ sub dbupgrade { return; } -# Check if we need an upgrade -sub need_upgrade { - if(!defined($options{version})) { return 1; } - - if($options{version} ne $version) { - return 1; - } else { - return 0; - } -} - -# Functions - sub get_option { + my ($name) = (@_); + if(keys (%options) == 0) { - my $sql = "select name, value from $tbl_options"; - my $sth = $dbh->prepare($sql); - $sth->execute() or die $DBI::errstr; + reload_options(); + } - while(my $hr = $sth->fetchrow_hashref) { - $options{$hr->{'name'}} = $hr->{'value'}; - } + # Determine if we need to upgrade the database + if($version ne $options{'version'}) { + print STDERR "Upgrading schema from $options{'version'} to $version.\n"; + dbupgrade(); + reload_options(); } - my ($name) = (@_); return $options{$name}; } +sub reload_options { + my $sql = "select name, value from $tbl_options"; + my $sth = $dbh->prepare($sql); + $sth->execute() or die $DBI::errstr; + + while(my $hr = $sth->fetchrow_hashref) { + $options{$hr->{'name'}} = $hr->{'value'}; + } +} + # This configures the URLs in the application to support mod_rewrite or # a webserver sans mod_rewrite. if(get_option('use_rewrite') eq 'yes') {