Land Coop's new schema. This makes some pretty wideranging changes and there's no upgrade path, so to upgrade from a previous db, wipe your database and start over. Schema changes by coop, Class::DBI wrangling by me.

This commit is contained in:
zach%zachlipton.com 2005-08-20 03:39:02 +00:00
parent 00e7890741
commit 208bbf31e9
18 changed files with 307 additions and 95 deletions

View File

@ -25,7 +25,7 @@ use strict;
do 'localconfig';
our $version = "0.0.1";
our $version = "0.0.2";
# if true, then Litmus will not accept any requests
our $disabled = 0;

View File

@ -26,7 +26,10 @@ use base 'Litmus::DBI';
Litmus::DB::Branch->table('branches');
Litmus::DB::Branch->columns(All => qw/branchid product name detect_regexp/);
Litmus::DB::Branch->columns(All => qw/branch_id product_id name detect_regexp/);
Litmus::DB::Branch->column_alias("branch_id", "branchid");
Litmus::DB::Branch->column_alias("product_id", "product");
Litmus::DB::Branch->has_many(testresults => "Litmus::DB::Testresult");
Litmus::DB::Branch->has_a(product => "Litmus::DB::Product");

View File

@ -28,9 +28,11 @@ use IO::File;
use Litmus::Error;
use Litmus;
Litmus::DB::Format->table('formats');
Litmus::DB::Format->table('test_format_lookup');
Litmus::DB::Format->columns(All => qw/formatid name/);
Litmus::DB::Format->columns(All => qw/format_id name/);
Litmus::DB::Format->column_alias("format_id", "formatid");
Litmus::DB::Format->has_many(tests => "Litmus::DB::Test");

View File

@ -26,7 +26,10 @@ use base 'Litmus::DBI';
Litmus::DB::Opsys->table('opsyses');
Litmus::DB::Opsys->columns(All => qw/opsysid platform name detect_regexp/);
Litmus::DB::Opsys->columns(All => qw/opsys_id platform_id name detect_regexp/);
Litmus::DB::Opsys->column_alias("opsys_id", "opsysid");
Litmus::DB::Opsys->column_alias("platform_id", "platform");
Litmus::DB::Opsys->has_many(testresults => "Litmus::DB::Testresult");
Litmus::DB::Opsys->has_a(platform => "Litmus::DB::Platform");

View File

@ -27,7 +27,10 @@ use CGI;
Litmus::DB::Platform->table('platforms');
Litmus::DB::Platform->columns(All => qw/platformid product name detect_regexp iconpath/);
Litmus::DB::Platform->columns(All => qw/platform_id product_id name detect_regexp iconpath/);
Litmus::DB::Platform->column_alias("platform_id", "platformid");
Litmus::DB::Platform->column_alias("product_id", "product");
Litmus::DB::Platform->has_a(product => "Litmus::DB::Product");
Litmus::DB::Platform->has_many(testresults => "Litmus::DB::Testresult");

View File

@ -26,7 +26,9 @@ use base 'Litmus::DBI';
Litmus::DB::Product->table('products');
Litmus::DB::Product->columns(All => qw/productid name iconpath/);
Litmus::DB::Product->columns(All => qw/product_id name iconpath/);
Litmus::DB::Product->column_alias("product_id", "productid");
Litmus::DB::Product->has_many(tests => "Litmus::DB::Test");
Litmus::DB::Product->has_many(testgroups => "Litmus::DB::Testgroup");

View File

@ -24,9 +24,11 @@ package Litmus::DB::Result;
use strict;
use base 'Litmus::DBI';
Litmus::DB::Result->table('results');
Litmus::DB::Result->table('test_result_status_lookup');
Litmus::DB::Result->columns(All => qw/resultid name style/);
Litmus::DB::Result->columns(All => qw/result_status_id name style/);
Litmus::DB::Result->column_alias("result_status_id", "resultid");
Litmus::DB::Result->has_many(testresults => "Litmus::DB::Testresult");

View File

@ -24,9 +24,11 @@ package Litmus::DB::Status;
use strict;
use base 'Litmus::DBI';
Litmus::DB::Status->table('statuses');
Litmus::DB::Status->table('test_status_lookup');
Litmus::DB::Status->columns(All => qw/statusid name/);
Litmus::DB::Status->columns(All => qw/test_status_id name/);
Litmus::DB::Status->column_alias("test_status_id", "statusid");
Litmus::DB::Status->has_many(tests => "Litmus::DB::Test");

View File

@ -30,7 +30,10 @@ use Litmus::DB::Testresult;
Litmus::DB::Subgroup->table('subgroups');
Litmus::DB::Subgroup->columns(All => qw/subgroupid testgroup name/);
Litmus::DB::Subgroup->columns(All => qw/subgroup_id testgroup_id name/);
Litmus::DB::Subgroup->column_alias("subgroup_id", "subgroupid");
Litmus::DB::Subgroup->column_alias("testgroup_id", "testgroup");
Litmus::DB::Subgroup->has_a(testgroup => "Litmus::DB::Testgroup");

View File

@ -30,15 +30,21 @@ use Litmus::Error;
Litmus::DB::Test->table('tests');
Litmus::DB::Test->columns(Primary => qw/testid/);
Litmus::DB::Test->columns(Essential => qw/testid subgroup summary status communityenabled format/);
Litmus::DB::Test->columns(All => qw/t1 t2 t3 s1 s2 i1 i2/);
Litmus::DB::Test->columns(Primary => qw/test_id/);
Litmus::DB::Test->columns(Essential => qw/subgroup_id summary details status_id community_enabled format_id regression_bug_id/);
Litmus::DB::Test->columns(All => qw/t1 t2 t3/);
Litmus::DB::Test->column_alias("test_id", "testid");
Litmus::DB::Test->column_alias("subgroup_id", "subgroup");
Litmus::DB::Test->column_alias("status_id", "status");
Litmus::DB::Test->column_alias("community_enabled", "communityenabled");
Litmus::DB::Test->column_alias("format_id", "format");
Litmus::DB::Test->has_a(subgroup => "Litmus::DB::Subgroup");
Litmus::DB::Test->has_a(status => "Litmus::DB::Status");
Litmus::DB::Test->has_a("format" => "Litmus::DB::Format");
Litmus::DB::Test->has_many(testresults => "Litmus::DB::Testresult", {order_by => 'timestamp DESC'});
Litmus::DB::Test->has_many(testresults => "Litmus::DB::Testresult", {order_by => 'submission_time DESC'});
# we override Class::DBI's find_column() so that when we refer to
# formatted names like steps and expected results, we use the actual
@ -48,17 +54,17 @@ sub find_column {
my $self = shift;
my $want = shift;
my $col;
my $col = undef;
if (ref $self) {
$want =~ s/^.*::(\w+)$/$1/;
$col = $self->format()->getColumnMapping($want);
$col = $self->format_id()->getColumnMapping($want);
}
if ($col) {
return $self->SUPER::find_column($col);
} else {
# didn't find it, so we fall back on the normal
# find_column:
# find_column from Litmus::DBI:
$self->SUPER::find_column($want);
}
}
@ -74,7 +80,7 @@ sub AUTOLOAD {
my $col = $self->find_column($name);
if (!$col) {
internalError("tried to call Litmus::DB::Test method $name which does not exist ");
internalError("tried to call Litmus::DB::Test method $name which does not exist");
}
return $self->$col(@args);

View File

@ -24,9 +24,13 @@ package Litmus::DB::Testgroup;
use strict;
use base 'Litmus::DBI';
Litmus::DB::Testgroup->table('testgroups');
Litmus::DB::Testgroup->table('test_groups');
Litmus::DB::Testgroup->columns(All => qw/testgroupid product name expirationdays/);
Litmus::DB::Testgroup->columns(All => qw/testgroup_id product_id name expiration_days/);
Litmus::DB::Testgroup->column_alias("testgroup_id", "testgroupid");
Litmus::DB::Testgroup->column_alias("product_id", "product");
Litmus::DB::Testgroup->column_alias("expiration_days", "expirationdays");
Litmus::DB::Testgroup->has_a(product => "Litmus::DB::Product");

View File

@ -28,9 +28,20 @@ use Time::Piece;
use Time::Seconds;
use Memoize;
Litmus::DB::Testresult->table('testresults');
Litmus::DB::Testresult->table('test_results');
Litmus::DB::Testresult->columns(All => qw/testresultid platform opsys branch buildid useragent result note user testid timestamp/);
Litmus::DB::Testresult->columns(All => qw/testresult_id test_id last_updated submission_time user_id platform_id opsys_id branch_id buildid user_agent result_id log_id/);
Litmus::DB::Testresult->column_alias("testresult_id", "testresultid");
Litmus::DB::Testresult->column_alias("test_id", "testid");
Litmus::DB::Testresult->column_alias("submission_time", "timestamp");
Litmus::DB::Testresult->column_alias("user_id", "user");
Litmus::DB::Testresult->column_alias("platform_id", "platform");
Litmus::DB::Testresult->column_alias("opsys_id", "opsys");
Litmus::DB::Testresult->column_alias("branch_id", "branch");
Litmus::DB::Testresult->column_alias("user_agent", "useragent");
Litmus::DB::Testresult->column_alias("result_id", "result");
Litmus::DB::Testresult->column_alias("log_id", "log");
Litmus::DB::Testresult->has_a(platform => "Litmus::DB::Platform");
@ -40,9 +51,28 @@ Litmus::DB::Testresult->has_a(testid => "Litmus::DB::Test");
Litmus::DB::Testresult->has_a(result => "Litmus::DB::Result");
Litmus::DB::Testresult->has_a(user => "Litmus::DB::User");
Litmus::DB::Testresult->has_a(useragent => "Litmus::UserAgentDetect");
Litmus::DB::Testresult->has_a("log" => "Litmus::DB::Log");
Litmus::DB::Testresult->has_many(comments => "Litmus::DB::Comment", {order_by => 'submission_time'});
Litmus::DB::Testresult->has_many(bugs => "Litmus::DB::Resultbug", {order_by => 'submission_time DESC'});
Litmus::DB::Testresult->autoinflate(dates => 'Time::Piece');
# for historical reasons, note() is a shorthand way of saying "the text of the first
# comment on this result if that comment was submitted by the result submitter"
sub note {
my $self = shift;
my @comments = $self->comments();
if (@comments && @comments[0] &&
@comments[0]->user() == $self->user()) {
return $comments[0]->comment();
} else {
return undef;
}
}
# is this test result recent?
memoize('isrecent', NORMALIZER => sub {my $a=shift; return $a->testresultid()});
sub isrecent {

View File

@ -26,7 +26,10 @@ use base 'Litmus::DBI';
Litmus::DB::User->table('users');
Litmus::DB::User->columns(All => qw/userid email istrusted/);
Litmus::DB::User->columns(All => qw/user_id email is_trusted/);
Litmus::DB::User->column_alias("user_id", "userid");
Litmus::DB::User->column_alias("is_trusted", "istrusted");
Litmus::DB::User->has_many(testresults => "Litmus::DB::Testresult");

View File

@ -4,16 +4,62 @@ use strict;
use warnings;
use Litmus::Config;
use Litmus::Error;
use Memoize;
use base 'Class::DBI::mysql';
my $dsn = "dbi:mysql:$Litmus::Config::db_name:$Litmus::Config::db_host";
our %column_aliases;
Litmus::DBI->set_db('Main',
$dsn,
$Litmus::Config::db_user,
$Litmus::Config::db_pass);
# In some cases, we have column names that make sense from a database perspective
# (i.e. subgroup_id), but that don't make sense from a class/object perspective
# (where subgroup would be more appropriate). To handle this, we allow for
# Litmus::DBI's subclasses to set column aliases with the column_alias() sub.
# Takes the database column name and the alias name.
sub column_alias {
my ($self, $db_name, $alias_name) = @_;
$column_aliases{$alias_name} = $db_name;
}
# here's where the actual work happens. We consult our alias list
# (as created by calls to column_alias()) and substitute the
# database column if we find a match
memoize('find_column');
sub find_column {
my $self = shift;
my $wanted = shift;
if (ref $self) {
$wanted =~ s/^.*::(\w+)$/$1/;
}
if ($column_aliases{$wanted}) {
return $column_aliases{$wanted};
} else {
# not an alias, so we use the normal
# find_column() from Class::DBI
$self->SUPER::find_column($wanted);
}
}
sub AUTOLOAD {
my $self = shift;
my @args = @_;
my $name = our $AUTOLOAD;
my $col = $self->find_column($name);
if (!$col) {
internalEror("tried to call Litmus::DBI method $name which does not exist");
}
return $self->$col(@args);
}
1;

View File

@ -40,14 +40,14 @@ Litmus::DB::Platform->set_sql(detectplatform => qq{
FROM __TABLE__
WHERE
? REGEXP detect_regexp AND
product LIKE ?
product_id LIKE ?
});
Litmus::DB::Branch->set_sql(detectbranch => qq{
SELECT __ESSENTIAL__
FROM __TABLE__
WHERE
? REGEXP detect_regexp AND
product LIKE ?
product_id LIKE ?
});
# constructor. Optionally you can pass a UA string

View File

@ -2,94 +2,189 @@ create database litmus;
use litmus;
create table tests (
testid int not null primary key auto_increment,
subgroup smallint not null,
summary varchar(255),
status tinyint not null,
communityenabled boolean,
format tinyint not null,
t1 longtext,
test_id int(11) not null primary key auto_increment,
subgroup_id smallint(6) not null,
summary varchar(255) not null,
details text,
status_id tinyint(4) not null,
community_enabled boolean,
format_id tinyint(4) not null,
regression_bug_id int(11),
t1 longtext,
t2 longtext,
t3 longtext,
s1 varchar(255),
s2 varchar(255),
i1 mediumint,
i2 mediumint
INDEX(subgroup_id),
INDEX(summary),
INDEX(status_id),
INDEX(community_enabled),
INDEX(format_id),
INDEX(regression_bug_id),
INDEX(t1(255)),
INDEX(t2(255)),
INDEX(t3(255))
);
create table testresults (
testresultid int not null primary key auto_increment,
testid int not null,
timestamp datetime not null,
user int,
platform smallint,
opsys smallint,
branch smallint,
create table test_results (
testresult_id int(11) not null primary key auto_increment,
test_id int(11) not null,
last_updated datetime not null,
submission_time datetime not null,
user_id int(11),
platform_id smallint(6),
opsys_id smallint(6),
branch_id smallint(6),
buildid varchar(45),
useragent varchar(255),
result smallint,
note text
user_agent varchar(255),
result_id smallint(6),
log_id int(11),
INDEX (test_id),
INDEX (last_updated),
INDEX (submission_time),
INDEX (user_id),
INDEX (platform_id),
INDEX (opsys_id),
INDEX (branch_id),
INDEX (user_agent),
INDEX (result_id),
INDEX (log_id)
);
create table products (
productid tinyint not null primary key auto_increment,
product_id tinyint not null primary key auto_increment,
name varchar(64) not null,
iconpath varchar(64)
iconpath varchar(255),
INDEX(name),
INDEX(iconpath)
);
create table testgroups (
testgroupid smallint not null primary key auto_increment,
product tinyint not null,
create table test_groups (
testgroup_id smallint(6) not null primary key auto_increment,
product_id tinyint(4) not null,
name varchar(64) not null,
expirationdays smallint not null
expiration_days smallint(6) not null,
INDEX(product_id),
INDEX(name),
INDEX(expiration_days)
);
create table subgroups (
subgroupid smallint not null primary key auto_increment,
testgroup smallint not null,
name varchar(64) not null
subgroup_id smallint(6) not null primary key auto_increment,
testgroup_id smallint(6) not null,
name varchar(64) not null,
INDEX(testgroup_id),
INDEX(name)
);
create table statuses (
statusid tinyint not null primary key auto_increment,
name varchar(64) not null
create table test_status_lookup (
test_status_id tinyint(4) not null primary key auto_increment,
name varchar(64) not null,
INDEX(name)
);
create table platforms (
platformid smallint not null primary key auto_increment,
product tinyint not null,
platform_id smallint(6) not null primary key auto_increment,
product_id tinyint(4) not null,
name varchar(64) not null,
detect_regexp varchar(255),
iconpath varchar(64)
iconpath varchar(255),
INDEX(product_id),
INDEX(name),
INDEX(detect_regexp),
INDEX(iconpath)
);
create table opsyses (
opsysid smallint not null primary key auto_increment,
platform smallint not null,
opsys_id smallint(6) not null primary key auto_increment,
platform_id smallint(6) not null,
name varchar(64) not null,
detect_regexp varchar(255)
detect_regexp varchar(255),
INDEX(platform_id),
INDEX(name),
INDEX(detect_regexp)
);
create table branches (
branchid smallint not null primary key auto_increment,
product tinyint not null,
branch_id smallint(6) not null primary key auto_increment,
product_id tinyint(4) not null,
name varchar(64) not null,
detect_regexp varchar(255)
detect_regexp varchar(255),
INDEX (product_id),
INDEX (name),
INDEX (detect_regexp)
);
create table results (
resultid smallint not null primary key auto_increment,
create table test_result_status_lookup (
result_status_id smallint(6) not null primary key auto_increment,
name varchar(64) not null,
style varchar(255) not null
style varchar(255) not null,
INDEX(name),
INDEX(style)
);
create table users (
userid int not null primary key auto_increment,
user_id int(11) not null primary key auto_increment,
email varchar(255) not null,
istrusted boolean
is_trusted boolean,
INDEX(email),
INDEX(is_trusted)
);
create table formats (
formatid tinyint not null primary key auto_increment,
name varchar(255) not null
create table test_format_lookup (
format_id tinyint(4) not null primary key auto_increment,
name varchar(255) not null,
INDEX(name)
);
create table test_result_bugs (
test_result_id int(11) not null auto_increment,
last_updated datetime not null,
submission_time datetime not null,
user_id int(11),
bug_id int(11),
PRIMARY KEY (test_result_id,bug_id),
INDEX(test_result_id),
INDEX(last_updated),
INDEX(submission_time),
INDEX(user_id)
);
create table test_result_comments (
comment_id int(11) not null primary key auto_increment,
test_result_id int(11) not null,
last_updated datetime not null,
submission_time datetime not null,
user_id int(11),
comment text,
INDEX(test_result_id),
INDEX(last_updated),
INDEX(submission_time),
INDEX(user_id)
);
create table test_result_logs (
log_id int(11) not null primary key auto_increment,
test_result_id int(11) not null,
last_updated datetime not null,
submission_time datetime not null,
log_path varchar(255),
INDEX(test_result_id),
INDEX(last_updated),
INDEX(submission_time),
INDEX(log_path)
);

View File

@ -124,18 +124,25 @@ foreach my $curtestid (@tests) {
$user = $user || Litmus::Auth::getCookie()->userid();
}
Litmus::DB::Testresult->create({
my $tr = Litmus::DB::Testresult->create({
user => $user,
testid => $curtest,
timestamp => $time,
useragent => $ua,
result => $result,
note => $note,
platform => $sysconfig->platform(),
opsys => $sysconfig->opsys(),
branch => $sysconfig->branch(),
buildid => $sysconfig->buildid(),
});
# if there's a note, create an entry in the comments table for it
Litmus::DB::Comment->create({
testresult => $tr,
submission_time => $time,
user => $user,
comment => $note
});
}
# process changes to testcases:

View File

@ -36,8 +36,9 @@ my $c = new CGI;
# how old of a build do we want to allow? default is 10 days
my $maxbuildage = 10;
# what branch do we accept? default is Deer Park
# what branch do we accept? default is the trunk or the 1.8 branch
my $branch = Litmus::DB::Branch->retrieve(1);
my $branch2 = Litmus::DB::Branch->retrieve(2);
showTest();
@ -51,27 +52,27 @@ sub showTest {
$time->date_separator("");
my $curbuildtime = $time->ymd;
my $prod = Litmus::DB::Product->search(name => "Firefox")->next();
my $branch = Litmus::DB::Branch->search(product => $prod, name => "Trunk")->next();
my @detectbranch = $ua->branch($prod);
if (! $ua->buildid() || ! $detectbranch[0] ||
$detectbranch[0]->branchid() != $branch->branchid() ||
$curbuildtime - $ua->buildid() > $maxbuildage) {
Litmus->template()->process("simpletest/simpletest.html.tmpl") ||
internalError(Litmus->template()->error());
exit;
if ((! $ua->buildid()) || (! $detectbranch[0]) ||
$curbuildtime - $ua->buildid() > $maxbuildage ||
($detectbranch[0]->branchid() != $branch->branchid() &&
$detectbranch[0]->branchid() != $branch2->branchid())) {
Litmus->template()->process("simpletest/simpletest.html.tmpl") ||
internalError(Litmus->template()->error());
exit;
}
my $pid = $prod->productid();
# get a random test to display:
Litmus::DB::Test->set_sql(random_test => qq {
SELECT __ESSENTIAL__
FROM __TABLE__, products,testgroups,subgroups
SELECT tests.test_id, tests.subgroup_id, tests.summary, tests.details, tests.status_id, tests.community_enabled, tests.format_id, tests.regression_bug_id
FROM __TABLE__, products,test_groups,subgroups
WHERE
products.productid=? AND
communityenabled = 1 AND
products.productid=testgroups.product AND
subgroups.testgroup=testgroups.testgroupid AND
tests.subgroup=subgroups.subgroupid
products.product_id=? AND
community_enabled = 1 AND
products.product_id=test_groups.product_id AND
subgroups.testgroup_id=test_groups.testgroup_id AND
tests.subgroup_id=subgroups.subgroup_id
ORDER BY RAND()
LIMIT 1
});