Open the DB using Hydra::Model::DB->new

This gets rid of the openHydraDB function and ensures that we
open the database in a consistent way.

Also drop the PostgreSQL sequence hacks.  They don't seem to be
necessary anymore.
This commit is contained in:
Eelco Dolstra
2012-03-13 12:10:19 +01:00
parent 914c5e248a
commit 179b012a8e
12 changed files with 31 additions and 79 deletions

View File

@ -6,6 +6,7 @@ use XML::Simple;
use POSIX qw(strftime);
use IPC::Run;
use Nix::Store;
use Hydra::Model::DB;
use Hydra::Helper::Nix;
use Digest::SHA qw(sha256_hex);
use File::Basename;
@ -22,7 +23,7 @@ our @EXPORT = qw(
sub scmPath {
return getHydraPath . "/scm" ;
return Hydra::Model::DB::getHydraPath . "/scm" ;
}

View File

@ -5,23 +5,17 @@ use Exporter;
use File::Path;
use File::Basename;
use Hydra::Helper::CatalystUtils;
use Hydra::Model::DB;
our @ISA = qw(Exporter);
our @EXPORT = qw(
getHydraPath getHydraHome getHydraDBPath openHydraDB getHydraConf txn_do
getHydraHome getHydraConf txn_do
registerRoot getGCRootsDir gcRootFor
getPrimaryBuildsForView
getPrimaryBuildTotal
getViewResult getLatestSuccessfulViewResult jobsetOverview removeAsciiEscapes);
sub getHydraPath {
my $dir = $ENV{"HYDRA_DATA"} || "/var/lib/hydra";
die "The HYDRA_DATA directory ($dir) does not exist!\n" unless -d $dir;
return $dir;
}
sub getHydraHome {
my $dir = $ENV{"HYDRA_HOME"} or die "The HYDRA_HOME directory does not exist!\n";
return $dir;
@ -29,33 +23,12 @@ sub getHydraHome {
sub getHydraConf {
my $conf = $ENV{"HYDRA_CONFIG"} || (getHydraPath . "/hydra.conf");
my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf");
die "The HYDRA_CONFIG file ($conf) does not exist!\n" unless -f $conf;
return $conf;
}
sub getHydraDBPath {
my $db = $ENV{"HYDRA_DBI"};
if ( defined $db ) {
return $db ;
}
else {
my $path = getHydraPath . '/hydra.sqlite';
die "The Hydra database ($path) not exist!\n" unless -f $path;
return "dbi:SQLite:$path";
}
}
sub openHydraDB {
my $db = Hydra::Schema->connect(getHydraDBPath, "", "", {});
$db->storage->dbh->do("PRAGMA synchronous = OFF;")
if defined $ENV{'HYDRA_NO_FSYNC'};
return $db;
}
# Awful hack to handle timeouts in SQLite: just retry the transaction.
# DBD::SQLite *has* a 30 second retry window, but apparently it
# doesn't work.