hydra/src/lib/Hydra/Schema/Builds.pm

232 lines
5.3 KiB
Perl
Raw Normal View History

2008-11-25 11:01:42 +00:00
package Hydra::Schema::Builds;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
2008-11-11 12:54:37 +00:00
__PACKAGE__->table("Builds");
__PACKAGE__->add_columns(
"id",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => undef,
},
2008-11-11 12:54:37 +00:00
"finished",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => undef,
},
"timestamp",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => undef,
},
2008-11-04 18:23:28 +00:00
"project",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
2008-11-04 18:23:28 +00:00
"jobset",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
"job",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
2008-11-12 16:42:07 +00:00
"nixname",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
"description",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
"drvpath",
{
data_type => "text",
default_value => undef,
is_nullable => 0,
size => undef,
},
"outpath",
{
data_type => "text",
default_value => undef,
is_nullable => 0,
size => undef,
},
2008-11-06 18:26:29 +00:00
"system",
{
data_type => "text",
default_value => undef,
is_nullable => 0,
size => undef,
},
"longdescription",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
"license",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
"homepage",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
"maintainers",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
);
__PACKAGE__->set_primary_key("id");
2008-11-25 11:01:42 +00:00
__PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" });
2008-11-10 10:18:50 +00:00
__PACKAGE__->belongs_to(
"jobset",
2008-11-25 11:01:42 +00:00
"Hydra::Schema::Jobsets",
2008-11-10 10:18:50 +00:00
{ name => "jobset", project => "project" },
);
2009-03-13 14:49:25 +00:00
__PACKAGE__->belongs_to(
"job",
"Hydra::Schema::Jobs",
{ jobset => "jobset", name => "job", project => "project" },
);
__PACKAGE__->might_have(
"buildschedulinginfo",
"Hydra::Schema::BuildSchedulingInfo",
2008-11-11 12:54:37 +00:00
{ "foreign.id" => "self.id" },
);
__PACKAGE__->might_have(
"buildresultinfo",
"Hydra::Schema::BuildResultInfo",
2008-11-11 12:54:37 +00:00
{ "foreign.id" => "self.id" },
);
2008-11-12 16:42:07 +00:00
__PACKAGE__->has_many(
"buildsteps",
"Hydra::Schema::BuildSteps",
{ "foreign.build" => "self.id" },
2008-11-12 16:42:07 +00:00
);
2008-11-11 12:54:37 +00:00
__PACKAGE__->has_many(
"buildinputs_builds",
"Hydra::Schema::BuildInputs",
2008-11-09 00:48:36 +00:00
{ "foreign.build" => "self.id" },
2008-11-08 22:40:12 +00:00
);
2008-11-11 12:54:37 +00:00
__PACKAGE__->has_many(
"buildinputs_dependencies",
"Hydra::Schema::BuildInputs",
2008-11-11 12:54:37 +00:00
{ "foreign.dependency" => "self.id" },
);
__PACKAGE__->has_many(
2008-11-12 16:42:07 +00:00
"buildproducts",
"Hydra::Schema::BuildProducts",
2008-11-09 00:48:36 +00:00
{ "foreign.build" => "self.id" },
);
# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-07-07 14:36:17
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mTc++yn7RST163jLNJkXaw
2008-11-11 12:54:37 +00:00
use Hydra::Helper::Nix;
__PACKAGE__->has_many(
"dependents",
"Hydra::Schema::BuildInputs",
{ "foreign.dependency" => "self.id" },
);
__PACKAGE__->many_to_many(dependentBuilds => 'dependents', 'build');
__PACKAGE__->has_many(
"inputs",
"Hydra::Schema::BuildInputs",
{ "foreign.build" => "self.id" },
);
2008-11-11 12:54:37 +00:00
__PACKAGE__->belongs_to(
"schedulingInfo",
"Hydra::Schema::BuildSchedulingInfo",
2008-11-11 12:54:37 +00:00
{ id => "id" },
);
__PACKAGE__->belongs_to(
"resultInfo",
"Hydra::Schema::BuildResultInfo",
2008-11-11 12:54:37 +00:00
{ id => "id" },
);
2008-11-06 13:40:31 +00:00
2009-05-11 13:56:52 +00:00
sub addSequence {
my $hydradbi = getHydraDBPath;
if ($hydradbi =~ m/^dbi:Pg/) {
__PACKAGE__->sequence('builds_id_seq');
}
}
sub makeSource {
my ($name, $query) = @_;
my $source = __PACKAGE__->result_source_instance();
my $new_source = $source->new($source);
$new_source->source_name($name);
$new_source->name(\ "($query)");
Hydra::Schema->register_extra_source($name => $new_source);
}
sub makeQueries {
my ($name, $constraint) = @_;
my $joinWithStatusChange =
"natural join BuildResultInfo r " .
"left join Builds b on b.id = " .
"(select max(id) from builds c natural join buildresultinfo r2 " .
" where x.project = c.project and x.jobset = c.jobset and x.job = c.job and x.system = c.system and " .
" x.id > c.id and r.buildstatus != r2.buildstatus)";
makeSource('JobStatus' . $name, "select *, b.id statusChangeId, b.timestamp statusChangeTime from (select project, jobset, job, system, max(id) as id from Builds where finished = 1 $constraint group by project, jobset, job, system) as latest natural join Builds x $joinWithStatusChange");
makeSource('LatestSucceeded' . $name, "select * from (select project, jobset, job, system, max(id) as id from Builds natural join BuildResultInfo where finished = 1 and buildStatus = 0 $constraint group by project, jobset, job, system) as latest natural join Builds x $joinWithStatusChange");
}
2009-05-11 13:56:52 +00:00
addSequence;
makeQueries('', "");
makeQueries('ForProject', "and project = ?");
makeQueries('ForJobset', "and project = ? and jobset = ?");
makeQueries('ForJob', "and project = ? and jobset = ? and job = ?");
1;