Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / CXGN / DB / Schemas.pm
blob40970dcfcdf08226c4047bf0f136bcfc81bbf53a
2 package CXGN::DB::Schemas;
4 use Moose;
6 use DBI;
7 use Bio::Chado::Schema;
8 use CXGN::Phenome::Schema;
9 use SGN::Schema;
10 use CXGN::Metadata::Schema;
13 has 'dbh' => (
14 is => 'rw',
17 has 'bcs_schema' => (isa => 'Bio::Chado::Schema',
18 is => 'rw',
21 has 'phenome_schema' => (isa => 'CXGN::Phenome::Schema',
22 is => 'rw',
25 has 'sgn_schema' => (isa => 'SGN::Schema',
26 is => 'rw',
29 has 'metadata_schema' => (isa => 'CXGN::Metadata::Schema',
30 is => 'rw',
33 has 'username' => (isa => 'Str',
34 is => 'rw',
37 has 'password' => (isa => 'Str',
38 is => 'rw',
41 has 'dbname' => (isa => 'Str',
42 is => 'rw',
45 has 'dbhost' => (isa => 'Str',
46 is => 'rw',
49 has 'dbuser' => (isa => 'Str',
50 is => 'rw',
53 has 'dbpass' => (isa => 'Str',
54 is => 'rw',
57 sub BUILD {
58 my $self = shift;
60 my $dsn = 'dbi:Pg:database='.$self->dbname().";host=".$self->dbhost().";port=5432";
62 if (! $self->dbh()) {
63 if (!$self->dbuser() && !$self->dbpass()) {
64 die "Need dbuser and dbpass";
66 $self->dbh(DBI->connect($dsn, $self->dbuser(), $self->dbpass()));
69 print STDERR "Setting the search path...\n";
70 $self->dbh()->do("SET search_path TO phenome, metadata, sgn_people, public, sgn");
72 print STDERR "Connecting to the schemas...\n";
73 $self->bcs_schema(Bio::Chado::Schema->connect( sub { $self->dbh(); }));
75 $self->phenome_schema(CXGN::Phenome::Schema->connect( sub { $self->dbh() }));
78 $self->sgn_schema(SGN::Schema->connect( sub { $self->dbh(); }));
80 $self->metadata_schema(CXGN::Metadata::Schema->connect( sub { $self->dbh(); }));