← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/flatten-bfj-3-query into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/flatten-bfj-3-query into lp:launchpad with lp:~wgrant/launchpad/flatten-bfj-2-garbo as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #758258 in Launchpad itself: "buildfarmjob schema is inefficient for reporting"
  https://bugs.launchpad.net/launchpad/+bug/758258

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/flatten-bfj-3-query/+merge/145543

The build farm job schema is being reworked to improve performance. Columns from PackageBuild and BuildFarmJob are being merged into tables that previously delegated to them. The PackageBuild table will end up dying entirely, but BuildFarmJob will remain, a shadow of its former self, to answer questions about Archive:+builds and Builder:+history. Additionally, BinaryPackageBuild is growing new distribution, distroseries, sourcepackagename and is_distro_archive columns to make searches even faster.

This branch (which can only land once the garbo jobs have completed) changes the app to read values from the new denormed columns, while still writing to the old ones on PB/BFJ during the transition. Most queries involving BuildFarmJob or PackageBuild are now just over BPB/SPRB/TTB.
-- 
https://code.launchpad.net/~wgrant/launchpad/flatten-bfj-3-query/+merge/145543
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/flatten-bfj-3-query into lp:launchpad.
=== modified file 'database/sampledata/current-dev.sql'
--- database/sampledata/current-dev.sql	2013-01-17 11:57:53 +0000
+++ database/sampledata/current-dev.sql	2013-02-01 02:30:31 +0000
@@ -2464,30 +2464,30 @@
 
 ALTER TABLE buildfarmjob DISABLE TRIGGER ALL;
 
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (2, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (6, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (7, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (8, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (9, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (10, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (11, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (12, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (13, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (14, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (15, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (16, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (18, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (19, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (21, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (22, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (23, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (24, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (25, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (26, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (27, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (28, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (29, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (30, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, 1, 0);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (2, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (6, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (7, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (8, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (9, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (10, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (11, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (12, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (13, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (14, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (15, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (16, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (18, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (19, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (21, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (22, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (23, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (24, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, 1, 0, 11);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (25, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (26, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (27, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (28, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (29, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, 1, 0, 12);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (30, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, 1, 0, 1);
 
 
 ALTER TABLE buildfarmjob ENABLE TRIGGER ALL;
@@ -2719,30 +2719,30 @@
 
 ALTER TABLE binarypackagebuild DISABLE TRIGGER ALL;
 
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (2, 1, 1, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (6, 2, 1, 32);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (7, 3, 6, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (8, 4, 6, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (9, 5, 1, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (10, 6, 1, 26);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (11, 7, 6, 25);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (12, 8, 6, 27);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (13, 9, 1, 17);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (14, 10, 1, 28);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (15, 11, 1, 29);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (16, 12, 11, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (18, 13, 8, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (19, 14, 8, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (21, 15, 1, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (22, 16, 8, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (23, 17, 1, 35);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (24, 18, 1, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (25, 19, 1, 35);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (26, 20, 8, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (27, 21, 1, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (28, 22, 12, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (29, 23, 8, 36);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (30, 24, 12, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (2, 1, 1, 14, 1, 0, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, NULL, NULL, 0, 2, 1, 1, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (6, 2, 1, 32, 1, 0, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 6, 1, 1, true, 23);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (7, 3, 6, 20, 1, 0, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, NULL, NULL, 0, 7, 1, 3, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (8, 4, 6, 14, 1, 0, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, NULL, NULL, 0, 8, 1, 3, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (9, 5, 1, 20, 1, 0, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 9, 1, 1, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (10, 6, 1, 26, 1, 0, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 10, 1, 1, true, 20);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (11, 7, 6, 25, 1, 0, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 11, 1, 3, true, 19);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (12, 8, 6, 27, 1, 0, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, NULL, 'cpp (>= 4:4.0.1-3), gcc-4.0 (>= 4.0.1-2)', 0, 12, 1, 3, true, 21);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (13, 9, 1, 17, 1, 0, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, NULL, NULL, 0, 13, 1, 1, true, 10);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (14, 10, 1, 28, 1, 0, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, NULL, NULL, 0, 14, 1, 1, true, 22);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (15, 11, 1, 29, 1, 0, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, NULL, NULL, 0, 15, 1, 1, true, 17);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (16, 12, 11, 20, 1, 0, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, NULL, NULL, 0, 16, 1, 3, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (18, 13, 8, 14, 1, 0, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, NULL, NULL, 0, 18, 1, 10, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (19, 14, 8, 20, 1, 0, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, NULL, NULL, 0, 19, 1, 10, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (21, 15, 1, 33, 1, 0, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, NULL, NULL, 0, 21, 1, 1, true, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (22, 16, 8, 33, 1, 0, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 91, NULL, 0, 22, 1, 10, true, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (23, 17, 1, 35, 1, 0, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 23, 1, 1, true, 26);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (24, 18, 1, 33, 11, 0, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 24, 1, 1, false, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (25, 19, 1, 35, 9, 0, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 25, 1, 1, false, 26);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (26, 20, 8, 33, 9, 0, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 26, 1, 10, false, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (27, 21, 1, 20, 9, 0, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, NULL, NULL, 0, 27, 1, 1, false, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (28, 22, 12, 14, 9, 0, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, NULL, NULL, 0, 28, 1, 1, false, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (29, 23, 8, 36, 12, 0, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, NULL, NULL, 0, 29, 1, 10, true, 27);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (30, 24, 12, 14, 1, 0, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, NULL, NULL, 0, 30, 1, 1, true, 1);
 
 
 ALTER TABLE binarypackagebuild ENABLE TRIGGER ALL;

=== modified file 'database/sampledata/current.sql'
--- database/sampledata/current.sql	2013-01-17 11:57:53 +0000
+++ database/sampledata/current.sql	2013-02-01 02:30:31 +0000
@@ -2459,30 +2459,30 @@
 
 ALTER TABLE buildfarmjob DISABLE TRIGGER ALL;
 
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (2, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (6, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (7, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (8, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (9, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (10, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (11, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (12, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (13, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (14, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (15, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (16, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (18, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (19, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (21, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (22, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (23, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (24, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (25, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (26, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (27, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (28, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (29, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, 1, 0);
-INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count) VALUES (30, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, 1, 0);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (2, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (6, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (7, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (8, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (9, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (10, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (11, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (12, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (13, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (14, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (15, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (16, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (18, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (19, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (21, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (22, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (23, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 1);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (24, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, 1, 0, 11);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (25, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (26, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (27, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (28, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, 1, 0, 9);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (29, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, 1, 0, 12);
+INSERT INTO buildfarmjob (id, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, job_type, failure_count, archive) VALUES (30, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, 1, 0, 1);
 
 
 ALTER TABLE buildfarmjob ENABLE TRIGGER ALL;
@@ -2656,30 +2656,30 @@
 
 ALTER TABLE binarypackagebuild DISABLE TRIGGER ALL;
 
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (2, 1, 1, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (6, 2, 1, 32);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (7, 3, 6, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (8, 4, 6, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (9, 5, 1, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (10, 6, 1, 26);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (11, 7, 6, 25);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (12, 8, 6, 27);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (13, 9, 1, 17);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (14, 10, 1, 28);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (15, 11, 1, 29);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (16, 12, 11, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (18, 13, 8, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (19, 14, 8, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (21, 15, 1, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (22, 16, 8, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (23, 17, 1, 35);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (24, 18, 1, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (25, 19, 1, 35);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (26, 20, 8, 33);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (27, 21, 1, 20);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (28, 22, 12, 14);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (29, 23, 8, 36);
-INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release) VALUES (30, 24, 12, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (2, 1, 1, 14, 1, 0, 1, false, '2004-09-27 11:57:13', '2004-09-27 11:55:13', '2004-09-27 11:57:14', NULL, 1, 1, 1, NULL, NULL, 0, 2, 1, 1, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (6, 2, 1, 32, 1, 0, 1, false, '2006-12-01 00:00:00', '2006-12-01 00:00:00', '2006-12-01 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 6, 1, 1, true, 23);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (7, 3, 6, 20, 1, 0, 1, false, '2005-03-24 00:00:00', '2005-03-24 23:58:43', '2005-03-25 00:00:03', NULL, 1, 1, 1, NULL, NULL, 0, 7, 1, 3, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (8, 4, 6, 14, 1, 0, 1, false, '2005-09-30 00:00:00', NULL, NULL, NULL, NULL, 6, NULL, NULL, NULL, 0, 8, 1, 3, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (9, 5, 1, 20, 1, 0, 1, false, '2005-10-01 00:00:00', '2005-10-01 23:56:41', '2005-10-02 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 9, 1, 1, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (10, 6, 1, 26, 1, 0, 1, false, '2006-01-27 00:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 10, 1, 1, true, 20);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (11, 7, 6, 25, 1, 0, 1, false, '2006-02-14 00:00:00', NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 11, 1, 3, true, 19);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (12, 8, 6, 27, 1, 0, 1, false, '2006-02-28 00:00:00', '2006-02-27 23:53:59', '2006-02-28 00:00:01', NULL, 1, 3, 1, NULL, 'cpp (>= 4:4.0.1-3), gcc-4.0 (>= 4.0.1-2)', 0, 12, 1, 3, true, 21);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (13, 9, 1, 17, 1, 0, 1, false, '2006-03-21 00:00:00', '2006-03-21 00:58:33', '2006-03-21 01:00:03', NULL, 1, 5, 1, NULL, NULL, 0, 13, 1, 1, true, 10);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (14, 10, 1, 28, 1, 0, 1, false, '2006-03-22 00:00:00', '2006-03-21 00:58:32', '2006-03-21 01:00:02', NULL, 1, 5, 1, NULL, NULL, 0, 14, 1, 1, true, 22);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (15, 11, 1, 29, 1, 0, 1, false, '2006-03-22 00:00:01', '2006-03-21 00:58:30', '2006-03-21 01:00:00', NULL, 1, 5, 1, NULL, NULL, 0, 15, 1, 1, true, 17);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (16, 12, 11, 20, 1, 0, 1, false, '2005-03-24 00:00:01', '2005-03-24 23:58:42', '2005-03-25 00:00:02', NULL, 1, 1, 1, NULL, NULL, 0, 16, 1, 3, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (18, 13, 8, 14, 1, 0, 1, false, '2004-09-27 11:57:14', '2004-09-27 11:55:12', '2004-09-27 11:57:13', NULL, 1, 1, 1, NULL, NULL, 0, 18, 1, 10, true, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (19, 14, 8, 20, 1, 0, 1, false, '2005-03-24 00:00:02', '2005-03-24 23:58:41', '2005-03-25 00:00:01', NULL, 1, 1, 1, NULL, NULL, 0, 19, 1, 10, true, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (21, 15, 1, 33, 1, 0, 1, false, '2006-12-01 00:00:01', NULL, NULL, NULL, NULL, 2, NULL, NULL, NULL, 0, 21, 1, 1, true, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (22, 16, 8, 33, 1, 0, 1, false, '2007-04-20 00:00:00', '2007-04-19 23:58:41', '2007-04-20 00:00:01', NULL, 1, 7, 1, 91, NULL, 0, 22, 1, 10, true, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (23, 17, 1, 35, 1, 0, 1, false, '2006-04-11 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 23, 1, 1, true, 26);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (24, 18, 1, 33, 11, 0, 1, true, '2007-05-30 00:00:00', '2007-05-29 23:58:41', '2007-05-30 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 24, 1, 1, false, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (25, 19, 1, 35, 9, 0, 1, true, '2007-07-08 12:00:00', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 0, 25, 1, 1, false, 26);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (26, 20, 8, 33, 9, 0, 1, true, '2007-07-08 00:00:00', '2007-07-07 23:58:41', '2007-07-08 00:00:01', NULL, 1, 2, 1, NULL, NULL, 0, 26, 1, 10, false, 24);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (27, 21, 1, 20, 9, 0, 1, true, '2007-07-24 00:00:00', '2007-07-23 23:58:41', '2007-07-24 00:00:01', NULL, 1, 1, 1, NULL, NULL, 0, 27, 1, 1, false, 14);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (28, 22, 12, 14, 9, 0, 3, true, '2007-08-10 00:00:00', '2007-08-10 00:00:00', '2007-08-10 00:00:13', NULL, 1, 1, 1, NULL, NULL, 0, 28, 1, 1, false, 1);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (29, 23, 8, 36, 12, 0, 1, false, '2007-08-09 21:54:18.553132', '2007-08-09 23:49:59', '2007-08-09 23:59:59', NULL, NULL, 1, NULL, NULL, NULL, 0, 29, 1, 10, true, 27);
+INSERT INTO binarypackagebuild (id, package_build, distro_arch_series, source_package_release, archive, pocket, processor, virtualized, date_created, date_started, date_finished, date_first_dispatched, builder, status, log, upload_log, dependencies, failure_count, build_farm_job, distribution, distro_series, is_distro_archive, source_package_name) VALUES (30, 24, 12, 14, 1, 0, 3, false, '2007-08-10 00:00:01', '2007-08-10 00:00:01', '2007-08-10 00:00:14', NULL, 1, 1, 1, NULL, NULL, 0, 30, 1, 1, true, 1);
 
 
 ALTER TABLE binarypackagebuild ENABLE TRIGGER ALL;

=== modified file 'lib/lp/buildmaster/interfaces/buildfarmjob.py'
--- lib/lp/buildmaster/interfaces/buildfarmjob.py	2013-01-22 08:31:09 +0000
+++ lib/lp/buildmaster/interfaces/buildfarmjob.py	2013-02-01 02:30:31 +0000
@@ -179,6 +179,8 @@
 
     id = Attribute('The build farm job ID.')
 
+    build_farm_job = Attribute('Generic build farm job record')
+
     processor = Reference(
         IProcessor, title=_("Processor"), required=False, readonly=True,
         description=_(

=== modified file 'lib/lp/buildmaster/interfaces/packagebuild.py'
--- lib/lp/buildmaster/interfaces/packagebuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/buildmaster/interfaces/packagebuild.py	2013-02-01 02:30:31 +0000
@@ -72,10 +72,6 @@
             description=_("A URL for failed upload logs."
                           "Will be None if there was no failure.")))
 
-    build_farm_job = Reference(
-        title=_('Build farm job'), schema=IBuildFarmJob, required=True,
-        readonly=True, description=_('The base build farm job.'))
-
     current_component = Attribute(
         'Component where the source related to this build was last '
         'published.')

=== modified file 'lib/lp/buildmaster/model/buildfarmjob.py'
--- lib/lp/buildmaster/model/buildfarmjob.py	2013-02-01 02:30:31 +0000
+++ lib/lp/buildmaster/model/buildfarmjob.py	2013-02-01 02:30:31 +0000
@@ -199,8 +199,6 @@
     archive_id = Int(name='archive')
     archive = Reference(archive_id, 'Archive.id')
 
-    dependencies = None
-
     def __init__(self, job_type, status=BuildStatus.NEEDSBUILD,
                  processor=None, virtualized=None, date_created=None,
                  builder=None, archive=None):
@@ -227,51 +225,47 @@
 
     @property
     def processor(self):
-        return self.build_farm_job.processor
+        return self._new_processor
 
     @property
     def virtualized(self):
-        return self.build_farm_job.virtualized
+        return self._new_virtualized
 
     @property
     def date_created(self):
-        return self.build_farm_job.date_created
+        return self._new_date_created
 
     @property
     def date_started(self):
-        return self.build_farm_job.date_started
+        return self._new_date_started
 
     @property
     def date_finished(self):
-        return self.build_farm_job.date_finished
+        return self._new_date_finished
 
     @property
     def date_first_dispatched(self):
-        return self.build_farm_job.date_first_dispatched
+        return self._new_date_first_dispatched
 
     @property
     def builder(self):
-        return self.build_farm_job.builder
+        return self._new_builder
 
     @property
     def status(self):
-        return self.build_farm_job.status
+        return self._new_status
 
     @property
     def log(self):
-        return self.build_farm_job.log
-
-    @property
-    def job_type(self):
-        return self.build_farm_job.job_type
+        return self._new_log
 
     @property
     def failure_count(self):
-        return self.build_farm_job.failure_count
+        return self._new_failure_count
 
     @property
     def dependencies(self):
-        return self.build_farm_job.dependencies
+        return None
 
     @property
     def title(self):

=== modified file 'lib/lp/buildmaster/model/packagebuild.py'
--- lib/lp/buildmaster/model/packagebuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/buildmaster/model/packagebuild.py	2013-02-01 02:30:31 +0000
@@ -110,24 +110,20 @@
 class PackageBuildMixin(BuildFarmJobMixin):
 
     @property
-    def build_farm_job(self):
-        return self.package_build.build_farm_job
-
-    @property
     def archive(self):
-        return self.package_build.archive
+        return self._new_archive
 
     @property
     def pocket(self):
-        return self.package_build.pocket
+        return self._new_pocket
 
     @property
     def upload_log(self):
-        return self.package_build.upload_log
+        return self._new_upload_log
 
     @property
     def dependencies(self):
-        return self.package_build.dependencies
+        return self._new_dependencies
 
     @property
     def current_component(self):

=== modified file 'lib/lp/code/model/sourcepackagerecipe.py'
--- lib/lp/code/model/sourcepackagerecipe.py	2012-09-05 05:08:26 +0000
+++ lib/lp/code/model/sourcepackagerecipe.py	2013-02-01 02:30:31 +0000
@@ -17,8 +17,7 @@
 from pytz import utc
 from storm.expr import (
     And,
-    Join,
-    RightJoin,
+    LeftJoin,
     )
 from storm.locals import (
     Bool,
@@ -37,8 +36,6 @@
     )
 
 from lp.buildmaster.enums import BuildStatus
-from lp.buildmaster.model.buildfarmjob import BuildFarmJob
-from lp.buildmaster.model.packagebuild import PackageBuild
 from lp.code.errors import (
     BuildAlreadyPending,
     BuildNotAllowedForDistro,
@@ -215,24 +212,25 @@
         store.add(sprecipe)
         return sprecipe
 
-    @classmethod
-    def findStaleDailyBuilds(cls):
+    @staticmethod
+    def findStaleDailyBuilds():
         one_day_ago = datetime.now(utc) - timedelta(hours=23, minutes=50)
-        joins = RightJoin(
-            Join(
-                Join(SourcePackageRecipeBuild, PackageBuild,
-                    PackageBuild.id ==
-                    SourcePackageRecipeBuild.package_build_id),
-                BuildFarmJob,
-                And(BuildFarmJob.id == PackageBuild.build_farm_job_id,
-                    BuildFarmJob.date_created > one_day_ago)),
-            SourcePackageRecipe,
-            And(SourcePackageRecipeBuild.recipe == SourcePackageRecipe.id,
-                SourcePackageRecipe.daily_build_archive_id ==
-                    PackageBuild.archive_id))
-        return IStore(cls).using(joins).find(
-            cls, cls.is_stale == True, cls.build_daily == True,
-            BuildFarmJob.date_created == None).config(distinct=True)
+        joins = (
+            SourcePackageRecipe,
+            LeftJoin(
+                SourcePackageRecipeBuild,
+                And(SourcePackageRecipeBuild.recipe_id ==
+                        SourcePackageRecipe.id,
+                    SourcePackageRecipeBuild._new_archive_id ==
+                        SourcePackageRecipe.daily_build_archive_id,
+                    SourcePackageRecipeBuild._new_date_created > one_day_ago)),
+            )
+        return IStore(SourcePackageRecipe).using(*joins).find(
+            SourcePackageRecipe,
+            SourcePackageRecipe.is_stale == True,
+            SourcePackageRecipe.build_daily == True,
+            SourcePackageRecipeBuild._new_date_created == None,
+            ).config(distinct=True)
 
     @staticmethod
     def exists(owner, name):
@@ -288,10 +286,8 @@
         pending = IStore(self).find(SourcePackageRecipeBuild,
             SourcePackageRecipeBuild.recipe_id == self.id,
             SourcePackageRecipeBuild.distroseries_id == distroseries.id,
-            PackageBuild.archive_id == archive.id,
-            PackageBuild.id == SourcePackageRecipeBuild.package_build_id,
-            BuildFarmJob.id == PackageBuild.build_farm_job_id,
-            BuildFarmJob.status == BuildStatus.NEEDSBUILD)
+            SourcePackageRecipeBuild._new_archive_id == archive.id,
+            SourcePackageRecipeBuild._new_status == BuildStatus.NEEDSBUILD)
         if pending.any() is not None:
             raise BuildAlreadyPending(self, distroseries)
 
@@ -323,39 +319,42 @@
     @property
     def builds(self):
         """See `ISourcePackageRecipe`."""
-        order_by = (Desc(Greatest(
-                            BuildFarmJob.date_started,
-                            BuildFarmJob.date_finished)),
-                   Desc(BuildFarmJob.date_created), Desc(BuildFarmJob.id))
+        order_by = (
+            Desc(Greatest(
+                SourcePackageRecipeBuild._new_date_started,
+                SourcePackageRecipeBuild._new_date_finished)),
+            Desc(SourcePackageRecipeBuild._new_date_created),
+            Desc(SourcePackageRecipeBuild.id))
         return self._getBuilds(None, order_by)
 
     @property
     def completed_builds(self):
         """See `ISourcePackageRecipe`."""
-        filter_term = BuildFarmJob.status != BuildStatus.NEEDSBUILD
-        order_by = (Desc(Greatest(
-                            BuildFarmJob.date_started,
-                            BuildFarmJob.date_finished)),
-                   Desc(BuildFarmJob.id))
+        filter_term = (
+            SourcePackageRecipeBuild._new_status != BuildStatus.NEEDSBUILD)
+        order_by = (
+            Desc(Greatest(
+                SourcePackageRecipeBuild._new_date_started,
+                SourcePackageRecipeBuild._new_date_finished)),
+            Desc(SourcePackageRecipeBuild.id))
         return self._getBuilds(filter_term, order_by)
 
     @property
     def pending_builds(self):
         """See `ISourcePackageRecipe`."""
-        filter_term = BuildFarmJob.status == BuildStatus.NEEDSBUILD
+        filter_term = (
+            SourcePackageRecipeBuild._new_status == BuildStatus.NEEDSBUILD)
         # We want to order by date_created but this is the same as ordering
         # by id (since id increases monotonically) and is less expensive.
-        order_by = Desc(BuildFarmJob.id)
+        order_by = Desc(SourcePackageRecipeBuild.id)
         return self._getBuilds(filter_term, order_by)
 
     def _getBuilds(self, filter_term, order_by):
         """The actual query to get the builds."""
         query_args = [
             SourcePackageRecipeBuild.recipe == self,
-            SourcePackageRecipeBuild.package_build_id == PackageBuild.id,
-            PackageBuild.build_farm_job_id == BuildFarmJob.id,
-            And(PackageBuild.archive_id == Archive.id,
-                Archive._enabled == True),
+            SourcePackageRecipeBuild._new_archive_id == Archive.id,
+            Archive._enabled == True,
             ]
         if filter_term is not None:
             query_args.append(filter_term)
@@ -378,19 +377,17 @@
     def last_build(self):
         """See `ISourcePackageRecipeBuild`."""
         return self._getBuilds(
-            True, Desc(BuildFarmJob.date_finished)).first()
+            True, Desc(SourcePackageRecipeBuild._new_date_finished)).first()
 
     def getMedianBuildDuration(self):
         """Return the median duration of builds of this recipe."""
         store = IStore(self)
         result = store.find(
-            BuildFarmJob,
+            SourcePackageRecipeBuild,
             SourcePackageRecipeBuild.recipe == self.id,
-            BuildFarmJob.date_finished != None,
-            BuildFarmJob.id == PackageBuild.build_farm_job_id,
-            SourcePackageRecipeBuild.package_build_id == PackageBuild.id)
-        durations = [build.date_finished - build.date_started for build in
-                     result]
+            SourcePackageRecipeBuild._new_date_finished != None)
+        durations = [
+            build.date_finished - build.date_started for build in result]
         if len(durations) == 0:
             return None
         durations.sort(reverse=True)

=== modified file 'lib/lp/code/model/sourcepackagerecipebuild.py'
--- lib/lp/code/model/sourcepackagerecipebuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/code/model/sourcepackagerecipebuild.py	2013-02-01 02:30:31 +0000
@@ -93,6 +93,7 @@
     package_build = Reference(package_build_id, 'PackageBuild.id')
 
     build_farm_job_type = BuildFarmJobType.RECIPEBRANCHBUILD
+    job_type = build_farm_job_type
 
     id = Int(primary=True)
 
@@ -150,8 +151,8 @@
     requester = Reference(requester_id, 'Person.id')
 
     # Migrating from PackageBuild
-    _new_build_farm_job_id = Int(name='build_farm_job')
-    _new_build_farm_job = Reference(_new_build_farm_job_id, BuildFarmJob.id)
+    build_farm_job_id = Int(name='build_farm_job')
+    build_farm_job = Reference(build_farm_job_id, BuildFarmJob.id)
 
     _new_archive_id = Int(name='archive')
     _new_archive = Reference(_new_archive_id, 'Archive.id')
@@ -216,7 +217,7 @@
                  requester, archive, pocket, date_created):
         """Construct a SourcePackageRecipeBuild."""
         super(SourcePackageRecipeBuild, self).__init__()
-        self._new_build_farm_job = build_farm_job
+        self.build_farm_job = build_farm_job
         self.package_build = package_build
         self.distroseries = distroseries
         self.recipe = recipe
@@ -365,16 +366,13 @@
 
     @classmethod
     def getRecentBuilds(cls, requester, recipe, distroseries, _now=None):
-        from lp.buildmaster.model.buildfarmjob import BuildFarmJob
         if _now is None:
             _now = datetime.now(pytz.UTC)
         store = IMasterStore(SourcePackageRecipeBuild)
         old_threshold = _now - timedelta(days=1)
         return store.find(cls, cls.distroseries_id == distroseries.id,
             cls.requester_id == requester.id, cls.recipe_id == recipe.id,
-            BuildFarmJob.date_created > old_threshold,
-            BuildFarmJob.id == PackageBuild.build_farm_job_id,
-            PackageBuild.id == cls.package_build_id)
+            cls._new_date_created > old_threshold)
 
     def makeJob(self):
         """See `ISourcePackageRecipeBuildJob`."""

=== modified file 'lib/lp/registry/model/sourcepackage.py'
--- lib/lp/registry/model/sourcepackage.py	2012-11-26 08:33:03 +0000
+++ lib/lp/registry/model/sourcepackage.py	2013-02-01 02:30:31 +0000
@@ -601,8 +601,8 @@
         # binary_only parameter as a source package can only have
         # binary builds.
 
-        clauseTables = ['SourcePackageRelease', 'PackageBuild',
-                        'SourcePackagePublishingHistory']
+        clauseTables = [
+            'SourcePackageRelease', 'SourcePackagePublishingHistory']
 
         condition_clauses = ["""
         BinaryPackageBuild.source_package_release =
@@ -612,7 +612,7 @@
         SourcePackagePublishingHistory.archive IN %s AND
         SourcePackagePublishingHistory.sourcepackagerelease =
             SourcePackageRelease.id AND
-        SourcePackagePublishingHistory.archive = PackageBuild.archive
+        SourcePackagePublishingHistory.archive = BinaryPackageBuild.archive
         """ % sqlvalues(self.sourcepackagename,
                         self.distroseries,
                         list(self.distribution.all_distro_archive_ids))]
@@ -627,8 +627,8 @@
         # exclude gina-generated and security (dak-made) builds
         # buildstate == FULLYBUILT && datebuilt == null
         condition_clauses.append(
-            "NOT (BuildFarmJob.status=%s AND "
-            "     BuildFarmJob.date_finished is NULL)"
+            "NOT (BinaryPackageBuild.status=%s AND "
+            "     BinaryPackageBuild.date_finished is NULL)"
             % sqlvalues(BuildStatus.FULLYBUILT))
 
         # Ordering according status
@@ -648,9 +648,9 @@
             clauseTables.append('BuildQueue')
             condition_clauses.append('BuildQueue.job = BuildPackageJob.job')
         elif build_state == BuildStatus.SUPERSEDED or build_state is None:
-            orderBy = [Desc("BuildFarmJob.date_created")]
+            orderBy = [Desc("BinaryPackageBuild.date_created")]
         else:
-            orderBy = [Desc("BuildFarmJob.date_finished")]
+            orderBy = [Desc("BinaryPackageBuild.date_finished")]
 
         # Fallback to ordering by -id as a tie-breaker.
         orderBy.append(Desc("id"))

=== modified file 'lib/lp/soyuz/doc/sourcepackagerelease.txt'
--- lib/lp/soyuz/doc/sourcepackagerelease.txt	2012-07-05 09:04:09 +0000
+++ lib/lp/soyuz/doc/sourcepackagerelease.txt	2013-02-01 02:30:31 +0000
@@ -60,7 +60,6 @@
 Mozilla-firefox 0.9 has got some builds. including a PPA build.  The 'builds'
 property only returns the non-PPA builds.
 
-   >>> from lp.buildmaster.model.packagebuild import PackageBuild
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
    >>> from storm.store import Store
@@ -68,8 +67,7 @@
    >>> ff_ppa_build = Store.of(cprov_ppa).find(
    ...     BinaryPackageBuild,
    ...     BinaryPackageBuild.source_package_release == spr,
-   ...     BinaryPackageBuild.package_build == PackageBuild.id,
-   ...     PackageBuild.archive == cprov_ppa)
+   ...     BinaryPackageBuild._new_archive == cprov_ppa)
    >>> ff_ppa_build.count()
    1
    >>> ff_ppa_build[0].archive.purpose.name

=== modified file 'lib/lp/soyuz/interfaces/binarypackagebuild.py'
--- lib/lp/soyuz/interfaces/binarypackagebuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/soyuz/interfaces/binarypackagebuild.py	2013-02-01 02:30:31 +0000
@@ -63,10 +63,6 @@
     """A Build interface for items requiring launchpad.View."""
     id = Int(title=_('ID'), required=True, readonly=True)
 
-    package_build = Reference(
-        title=_('Package build'), schema=IPackageBuild, required=True,
-        readonly=True, description=_('The base package build'))
-
     # Overridden from IBuildFarmJob to ensure required is True.
     processor = Reference(
         title=_("Processor"), schema=IProcessor,

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2013-01-11 00:18:49 +0000
+++ lib/lp/soyuz/model/archive.py	2013-02-01 02:30:31 +0000
@@ -55,8 +55,6 @@
     )
 from lp.buildmaster.enums import BuildStatus
 from lp.buildmaster.interfaces.packagebuild import IPackageBuildSet
-from lp.buildmaster.model.buildfarmjob import BuildFarmJob
-from lp.buildmaster.model.packagebuild import PackageBuild
 from lp.registry.enums import (
     INCLUSIVE_TEAM_POLICY,
     PersonVisibility,
@@ -86,7 +84,10 @@
     IStoreSelector,
     MAIN_STORE,
     )
-from lp.services.database.lpstorm import ISlaveStore
+from lp.services.database.lpstorm import (
+    ISlaveStore,
+    IStore,
+    )
 from lp.services.database.sqlbase import (
     cursor,
     quote,
@@ -1117,20 +1118,17 @@
         extra_exprs = []
         if not include_needsbuild:
             extra_exprs.append(
-                BuildFarmJob.status != BuildStatus.NEEDSBUILD)
+                BinaryPackageBuild._new_status != BuildStatus.NEEDSBUILD)
 
         find_spec = (
-            BuildFarmJob.status,
+            BinaryPackageBuild._new_status,
             Count(BinaryPackageBuild.id),
             )
-        result = store.using(
-            BinaryPackageBuild, PackageBuild, BuildFarmJob).find(
+        result = store.find(
             find_spec,
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.archive == self,
-            PackageBuild.build_farm_job == BuildFarmJob.id,
-            *extra_exprs).group_by(BuildFarmJob.status).order_by(
-                BuildFarmJob.status)
+            BinaryPackageBuild._new_archive == self,
+            *extra_exprs).group_by(BinaryPackageBuild._new_status).order_by(
+                BinaryPackageBuild._new_status)
 
         # Create a map for each count summary to a number of buildstates:
         count_map = {
@@ -1898,18 +1896,14 @@
         """See `IArchive`."""
         store = Store.of(self)
 
-        base_query = (
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.archive == self,
-            PackageBuild.build_farm_job == BuildFarmJob.id)
         sprs_building = store.find(
             BinaryPackageBuild.source_package_release_id,
-            BuildFarmJob.status == BuildStatus.BUILDING,
-            *base_query)
+            BinaryPackageBuild._new_archive == self,
+            BinaryPackageBuild._new_status == BuildStatus.BUILDING)
         sprs_waiting = store.find(
             BinaryPackageBuild.source_package_release_id,
-            BuildFarmJob.status == BuildStatus.NEEDSBUILD,
-            *base_query)
+            BinaryPackageBuild._new_archive == self,
+            BinaryPackageBuild._new_status == BuildStatus.NEEDSBUILD)
 
         # A package is not counted as waiting if it already has at least
         # one build building.
@@ -1924,17 +1918,13 @@
 
         extra_exprs = []
         if build_status is not None:
-            extra_exprs = [
-                PackageBuild.build_farm_job == BuildFarmJob.id,
-                BuildFarmJob.status == build_status,
-                ]
+            extra_exprs = [BinaryPackageBuild._new_status == build_status]
 
         result_set = store.find(
             SourcePackageRelease,
             (BinaryPackageBuild.source_package_release_id ==
                 SourcePackageRelease.id),
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.archive == self,
+            BinaryPackageBuild._new_archive == self,
             *extra_exprs)
 
         result_set.config(distinct=True).order_by(SourcePackageRelease.id)
@@ -1974,18 +1964,15 @@
 
         query = """
             UPDATE Job SET status = %s
-            FROM BinaryPackageBuild, PackageBuild, BuildFarmJob,
-                 BuildPackageJob, BuildQueue
+            FROM BinaryPackageBuild, BuildPackageJob, BuildQueue
             WHERE
-                BinaryPackageBuild.package_build = PackageBuild.id
                 -- insert self.id here
-                AND PackageBuild.archive = %s
+                BinaryPackageBuild.archive = %s
                 AND BuildPackageJob.build = BinaryPackageBuild.id
                 AND BuildPackageJob.job = BuildQueue.job
                 AND Job.id = BuildQueue.job
                 -- Build is in state BuildStatus.NEEDSBUILD (0)
-                AND PackageBuild.build_farm_job = BuildFarmJob.id
-                AND BuildFarmJob.status = %s;
+                AND BinaryPackageBuild.status = %s;
         """ % sqlvalues(status, self, BuildStatus.NEEDSBUILD)
 
         store = Store.of(self)
@@ -2411,19 +2398,13 @@
 
     def getBuildCountersForArchitecture(self, archive, distroarchseries):
         """See `IArchiveSet`."""
-        cur = cursor()
-        query = """
-            SELECT BuildFarmJob.status, count(BuildFarmJob.id) FROM
-            BinaryPackageBuild, PackageBuild, BuildFarmJob
-            WHERE
-                BinaryPackageBuild.package_build = PackageBuild.id AND
-                PackageBuild.build_farm_job = BuildFarmJob.id AND
-                PackageBuild.archive = %s AND
-                BinaryPackageBuild.distro_arch_series = %s
-            GROUP BY BuildFarmJob.status ORDER BY BuildFarmJob.status;
-        """ % sqlvalues(archive, distroarchseries)
-        cur.execute(query)
-        result = cur.fetchall()
+        result = IStore(BinaryPackageBuild).find(
+            (BinaryPackageBuild._new_status, Count(BinaryPackageBuild.id)),
+            BinaryPackageBuild._new_archive == archive,
+            BinaryPackageBuild.distro_arch_series == distroarchseries,
+            ).group_by(
+                BinaryPackageBuild._new_status
+            ).order_by(BinaryPackageBuild._new_status)
 
         status_map = {
             'failed': (
@@ -2452,8 +2433,7 @@
         for key, status in status_map.iteritems():
             status_and_counters[key] = 0
             for status_value, status_counter in result:
-                status_values = [item.value for item in status]
-                if status_value in status_values:
+                if status_value in status:
                     status_and_counters[key] += status_counter
 
         return status_and_counters

=== modified file 'lib/lp/soyuz/model/binarypackagebuild.py'
--- lib/lp/soyuz/model/binarypackagebuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/soyuz/model/binarypackagebuild.py	2013-02-01 02:30:31 +0000
@@ -105,6 +105,7 @@
     _defaultOrder = 'id'
 
     build_farm_job_type = BuildFarmJobType.PACKAGEBUILD
+    job_type = build_farm_job_type
 
     package_build_id = Int(name='package_build', allow_none=False)
     package_build = Reference(package_build_id, 'PackageBuild.id')
@@ -118,8 +119,8 @@
         source_package_release_id, 'SourcePackageRelease.id')
 
     # Migrating from PackageBuild
-    _new_build_farm_job_id = Int(name='build_farm_job')
-    _new_build_farm_job = Reference(_new_build_farm_job_id, BuildFarmJob.id)
+    build_farm_job_id = Int(name='build_farm_job')
+    build_farm_job = Reference(build_farm_job_id, BuildFarmJob.id)
 
     _new_archive_id = Int(name='archive')
     _new_archive = Reference(_new_archive_id, 'Archive.id')
@@ -634,17 +635,14 @@
             BinaryPackageBuild.distro_arch_series = %s AND
             SourcePackageRelease.sourcepackagename = SourcePackageName.id AND
             SourcePackageName.name = %s AND
-            BinaryPackageBuild.package_build = PackageBuild.id AND
-            PackageBuild.archive IN %s AND
-            PackageBuild.build_farm_job = BuildFarmJob.id AND
-            BuildFarmJob.date_finished IS NOT NULL AND
-            BuildFarmJob.status = %s
+            BinaryPackageBuild.archive IN %s AND
+            BinaryPackageBuild.date_finished IS NOT NULL AND
+            BinaryPackageBuild.status = %s
             """ % sqlvalues(self, self.distro_arch_series,
                             self.source_package_release.name, archives,
                             BuildStatus.FULLYBUILT),
-            orderBy=['-BuildFarmJob.date_finished', '-id'],
-            clauseTables=['PackageBuild', 'BuildFarmJob', 'SourcePackageName',
-                          'SourcePackageRelease'])
+            orderBy=['-date_finished', '-id'],
+            clauseTables=['SourcePackageName', 'SourcePackageRelease'])
 
         estimated_duration = None
         if bool(completed_builds):
@@ -890,7 +888,7 @@
             build_farm_job, archive, pocket)
 
         binary_package_build = BinaryPackageBuild(
-            _new_build_farm_job=build_farm_job,
+            build_farm_job=build_farm_job,
             package_build=package_build,
             distro_arch_series=distro_arch_series,
             source_package_release=source_package_release,
@@ -995,23 +993,18 @@
         from lp.soyuz.model.distroarchseries import DistroArchSeries
         from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
 
-        # Ensure the underlying buildfarmjob and package build tables
-        # are included.
-        clauses.extend([
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.build_farm_job == BuildFarmJob.id])
-        origin.extend([BinaryPackageBuild, BuildFarmJob])
+        origin.append(BinaryPackageBuild)
 
         # Add query clause that filters on build state if the latter is
         # provided.
         if status is not None:
-            clauses.append(BuildFarmJob.status == status)
+            clauses.append(BinaryPackageBuild._new_status == status)
 
         # Add query clause that filters on pocket if the latter is provided.
         if pocket:
             if not isinstance(pocket, (list, tuple)):
                 pocket = (pocket,)
-            clauses.append(PackageBuild.pocket.is_in(pocket))
+            clauses.append(BinaryPackageBuild._new_pocket.is_in(pocket))
 
         # Add query clause that filters on architecture tag if provided.
         if arch_tag is not None:
@@ -1044,23 +1037,24 @@
             Archive, get_archive_privacy_filter)
 
         clauses = [
-            PackageBuild.archive_id == Archive.id,
-            BuildFarmJob.builder_id == builder_id,
+            BinaryPackageBuild._new_archive_id == Archive.id,
+            BinaryPackageBuild._new_builder_id == builder_id,
             get_archive_privacy_filter(user)]
-        origin = [PackageBuild, Archive]
+        origin = [Archive]
 
         self.handleOptionalParamsForBuildQueries(
             clauses, origin, status, name, pocket=None, arch_tag=arch_tag)
 
         return IStore(BinaryPackageBuild).using(*origin).find(
             BinaryPackageBuild, *clauses).order_by(
-                Desc(BuildFarmJob.date_finished), BinaryPackageBuild.id)
+                Desc(BinaryPackageBuild._new_date_finished),
+                BinaryPackageBuild.id)
 
     def getBuildsForArchive(self, archive, status=None, name=None,
                             pocket=None, arch_tag=None):
         """See `IBinaryPackageBuildSet`."""
-        clauses = [PackageBuild.archive_id == archive.id]
-        origin = [PackageBuild]
+        clauses = [BinaryPackageBuild._new_archive_id == archive.id]
+        origin = []
 
         self.handleOptionalParamsForBuildQueries(
             clauses, origin, status, name, pocket, arch_tag)
@@ -1070,9 +1064,9 @@
         # * FULLYBUILT & FAILURES by -datebuilt
         # It should present the builds in a more natural order.
         if status == BuildStatus.SUPERSEDED or status is None:
-            orderBy = [Desc(BuildFarmJob.date_created)]
+            orderBy = [Desc(BinaryPackageBuild._new_date_created)]
         else:
-            orderBy = [Desc(BuildFarmJob.date_finished)]
+            orderBy = [Desc(BinaryPackageBuild._new_date_finished)]
         # All orders fallback to id if the primary order doesn't succeed
         orderBy.append(BinaryPackageBuild.id)
 
@@ -1087,8 +1081,6 @@
         if not arch_ids:
             return EmptyResultSet()
 
-        clauseTables = [PackageBuild]
-
         # format clause according single/multiple architecture(s) form
         if len(arch_ids) == 1:
             condition_clauses = [('distro_arch_series=%s'
@@ -1097,10 +1089,6 @@
             condition_clauses = [('distro_arch_series IN %s'
                                   % sqlvalues(arch_ids))]
 
-        condition_clauses.extend([
-            "BinaryPackageBuild.package_build = PackageBuild.id",
-            "PackageBuild.build_farm_job = BuildFarmJob.id"])
-
         # XXX cprov 2006-09-25: It would be nice if we could encapsulate
         # the chunk of code below (which deals with the optional paramenters)
         # and share it with ISourcePackage.getBuildRecords()
@@ -1108,20 +1096,23 @@
         # exclude gina-generated and security (dak-made) builds
         # status == FULLYBUILT && datebuilt == null
         if status == BuildStatus.FULLYBUILT:
-            condition_clauses.append("BuildFarmJob.date_finished IS NOT NULL")
+            condition_clauses.append(
+                "BinaryPackageBuild.date_finished IS NOT NULL")
         else:
             condition_clauses.append(
-                "(BuildFarmJob.status <> %s OR "
-                " BuildFarmJob.date_finished IS NOT NULL)"
+                "(BinaryPackageBuild.status <> %s OR "
+                " BinaryPackageBuild.date_finished IS NOT NULL)"
                 % sqlvalues(BuildStatus.FULLYBUILT))
 
         # Ordering according status
         # * NEEDSBUILD, BUILDING & UPLOADING by -lastscore
-        # * SUPERSEDED & All by -PackageBuild.build_farm_job
+        # * SUPERSEDED & All by -BinaryPackageBuild.id
         #   (nearly equivalent to -datecreated, but much more
         #   efficient.)
         # * FULLYBUILT & FAILURES by -datebuilt
         # It should present the builds in a more natural order.
+        clauseTables = []
+        order_by_table = None
         if status in [
             BuildStatus.NEEDSBUILD,
             BuildStatus.BUILDING,
@@ -1134,12 +1125,10 @@
                 'BuildPackageJob.build = BinaryPackageBuild.id')
             condition_clauses.append('BuildPackageJob.job = BuildQueue.job')
         elif status == BuildStatus.SUPERSEDED or status is None:
-            order_by = [Desc(PackageBuild.build_farm_job_id)]
-            order_by_table = PackageBuild
+            order_by = [Desc(BinaryPackageBuild.id)]
         else:
-            order_by = [Desc(BuildFarmJob.date_finished),
+            order_by = [Desc(BinaryPackageBuild._new_date_finished),
                         BinaryPackageBuild.id]
-            order_by_table = BuildFarmJob
 
         # End of duplication (see XXX cprov 2006-09-25 above).
 
@@ -1149,11 +1138,14 @@
         # Only pick builds from the distribution's main archive to
         # exclude PPA builds
         condition_clauses.append(
-            "PackageBuild.archive IN %s" %
+            "BinaryPackageBuild.archive IN %s" %
             sqlvalues(list(distribution.all_distro_archive_ids)))
 
+        find_spec = (BinaryPackageBuild,)
+        if order_by_table:
+            find_spec = find_spec + (order_by_table,)
         result_set = Store.of(distribution).using(*clauseTables).find(
-            (BinaryPackageBuild, order_by_table), *condition_clauses)
+            find_spec, *condition_clauses)
         result_set.order_by(*order_by)
 
         def get_bpp(result_row):
@@ -1182,20 +1174,21 @@
         query = """
             source_package_release IN %s AND
             package_build = packagebuild.id AND
-            archive.id = packagebuild.archive AND
+            archive.id = binarypackagebuild.archive AND
             archive.purpose != %s AND
             packagebuild.build_farm_job = buildfarmjob.id
             """ % sqlvalues(sourcepackagerelease_ids, ArchivePurpose.PPA)
 
         if buildstate is not None:
-            query += "AND buildfarmjob.status = %s" % sqlvalues(buildstate)
+            query += (
+                "AND binarypackagebuild.status = %s" % sqlvalues(buildstate))
 
         resultset = IStore(BinaryPackageBuild).using(
             BinaryPackageBuild, PackageBuild, BuildFarmJob, Archive).find(
             (BinaryPackageBuild, PackageBuild, BuildFarmJob),
             SQL(query))
         resultset.order_by(
-            Desc(BuildFarmJob.date_created), BinaryPackageBuild.id)
+            Desc(BinaryPackageBuild._new_date_created), BinaryPackageBuild.id)
         return DecoratedResultSet(resultset, operator.itemgetter(0))
 
     def getStatusSummaryForBuilds(self, builds):

=== modified file 'lib/lp/soyuz/model/buildpackagejob.py'
--- lib/lp/soyuz/model/buildpackagejob.py	2013-01-22 06:42:23 +0000
+++ lib/lp/soyuz/model/buildpackagejob.py	2013-02-01 02:30:31 +0000
@@ -157,14 +157,13 @@
             )
         sub_query = """
             SELECT TRUE FROM Archive, BinaryPackageBuild, BuildPackageJob,
-                             PackageBuild, BuildFarmJob, DistroArchSeries
+                             DistroArchSeries
             WHERE
             BuildPackageJob.job = Job.id AND
             BuildPackageJob.build = BinaryPackageBuild.id AND
             BinaryPackageBuild.distro_arch_series =
                 DistroArchSeries.id AND
-            BinaryPackageBuild.package_build = PackageBuild.id AND
-            PackageBuild.archive = Archive.id AND
+            BinaryPackageBuild.archive = Archive.id AND
             ((Archive.private IS TRUE AND
               EXISTS (
                   SELECT SourcePackagePublishingHistory.id
@@ -178,8 +177,7 @@
                       SourcePackagePublishingHistory.status IN %s))
               OR
               archive.private IS FALSE) AND
-            PackageBuild.build_farm_job = BuildFarmJob.id AND
-            BuildFarmJob.status = %s
+            BinaryPackageBuild.status = %s
         """ % sqlvalues(private_statuses, BuildStatus.NEEDSBUILD)
 
         # Ensure that if BUILDING builds exist for the same
@@ -201,16 +199,12 @@
             sub_query += """
             AND Archive.id NOT IN (
                 SELECT Archive.id
-                FROM PackageBuild, BuildFarmJob, Archive,
-                    BinaryPackageBuild, DistroArchSeries
+                FROM Archive, BinaryPackageBuild, DistroArchSeries
                 WHERE
-                    PackageBuild.build_farm_job = BuildFarmJob.id
-                    AND BinaryPackageBuild.package_build = PackageBuild.id
-                    AND BinaryPackageBuild.distro_arch_series
-                        = DistroArchSeries.id
+                    BinaryPackageBuild.distro_arch_series = DistroArchSeries.id
                     AND DistroArchSeries.processorfamily = %s
-                    AND BuildFarmJob.status = %s
-                    AND PackageBuild.archive = Archive.id
+                    AND BinaryPackageBuild.status = %s
+                    AND BinaryPackageBuild.archive = Archive.id
                     AND Archive.purpose = %s
                     AND Archive.private IS FALSE
                 GROUP BY Archive.id

=== modified file 'lib/lp/soyuz/model/distributionsourcepackagerelease.py'
--- lib/lp/soyuz/model/distributionsourcepackagerelease.py	2013-01-07 02:40:55 +0000
+++ lib/lp/soyuz/model/distributionsourcepackagerelease.py	2013-02-01 02:30:31 +0000
@@ -20,8 +20,6 @@
 from storm.store import Store
 from zope.interface import implements
 
-from lp.buildmaster.model.buildfarmjob import BuildFarmJob
-from lp.buildmaster.model.packagebuild import PackageBuild
 from lp.services.database.decoratedresultset import DecoratedResultSet
 from lp.services.database.sqlbase import sqlvalues
 from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES
@@ -105,8 +103,6 @@
             BinaryPackageBuild.distro_arch_series == DistroArchSeries.id,
             DistroArchSeries.distroseries == DistroSeries.id,
             DistroSeries.distribution == self.distribution,
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.build_farm_job == BuildFarmJob.id
             )
 
         # First, get all the builds built in a main archive (this will
@@ -114,7 +110,7 @@
         builds_built_in_main_archives = Store.of(self.distribution).find(
             BinaryPackageBuild,
             builds_for_distro_exprs,
-            PackageBuild.archive == Archive.id,
+            BinaryPackageBuild._new_archive == Archive.id,
             Archive.purpose.is_in(MAIN_ARCHIVE_PURPOSES))
 
         # Next get all the builds that have a binary published in the

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2013-01-03 00:16:08 +0000
+++ lib/lp/soyuz/model/publishing.py	2013-02-01 02:30:31 +0000
@@ -1579,17 +1579,14 @@
         # If an optional list of build states was passed in as a parameter,
         # ensure that the result is limited to builds in those states.
         if build_states is not None:
-            extra_exprs.extend((
-                BinaryPackageBuild.package_build == PackageBuild.id,
-                PackageBuild.build_farm_job == BuildFarmJob.id,
-                BuildFarmJob.status.is_in(build_states)))
+            extra_exprs.append(
+                BinaryPackageBuild._new_status.is_in(build_states))
 
         store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
 
         # We'll be looking for builds in the same distroseries as the
         # SPPH for the same release.
         builds_for_distroseries_expr = (
-            BinaryPackageBuild.package_build == PackageBuild.id,
             BinaryPackageBuild.distro_arch_series_id == DistroArchSeries.id,
             SourcePackagePublishingHistory.distroseriesID ==
                 DistroArchSeries.distroseriesID,
@@ -1603,7 +1600,7 @@
             BinaryPackageBuild,
             builds_for_distroseries_expr,
             (SourcePackagePublishingHistory.archiveID ==
-                PackageBuild.archive_id),
+                BinaryPackageBuild._new_archive_id),
             *extra_exprs)
 
         # Next get all the builds that have a binary published in the
@@ -1613,7 +1610,7 @@
             BinaryPackageBuild,
             builds_for_distroseries_expr,
             (SourcePackagePublishingHistory.archiveID !=
-                PackageBuild.archive_id),
+                BinaryPackageBuild._new_archive_id),
             BinaryPackagePublishingHistory.archive ==
                 SourcePackagePublishingHistory.archiveID,
             BinaryPackagePublishingHistory.binarypackagerelease ==
@@ -1737,9 +1734,7 @@
             self._getSourceBinaryJoinForSources(
                 source_publication_ids, active_binaries_only=False),
             BinaryPackagePublishingHistory.datepublished != None,
-            BinaryPackageBuild.package_build == PackageBuild.id,
-            PackageBuild.build_farm_job == BuildFarmJob.id,
-            BuildFarmJob.status.is_in(build_states))
+            BinaryPackageBuild._new_status.is_in(build_states))
 
         published_builds.order_by(
             SourcePackagePublishingHistory.id,

=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
--- lib/lp/soyuz/model/sourcepackagerelease.py	2013-01-07 04:53:37 +0000
+++ lib/lp/soyuz/model/sourcepackagerelease.py	2013-02-01 02:30:31 +0000
@@ -226,13 +226,11 @@
         # sourcepackagerelease.
         return BinaryPackageBuild.select("""
             source_package_release = %s AND
-            package_build = packagebuild.id AND
-            archive.id = packagebuild.archive AND
-            packagebuild.build_farm_job = buildfarmjob.id AND
+            archive.id = binarypackagebuild.archive AND
             archive.purpose IN %s
             """ % sqlvalues(self.id, MAIN_ARCHIVE_PURPOSES),
-            orderBy=['-buildfarmjob.date_created', 'id'],
-            clauseTables=['Archive', 'PackageBuild', 'BuildFarmJob'])
+            orderBy=['-date_created', 'id'],
+            clauseTables=['Archive'])
 
     @property
     def age(self):
@@ -447,16 +445,10 @@
         # If there was no published binary we have to try to find a
         # suitable build in all possible location across the distroseries
         # inheritance tree. See below.
-        clause_tables = [
-            'BuildFarmJob',
-            'PackageBuild',
-            'DistroArchSeries',
-            ]
+        clause_tables = ['DistroArchSeries']
         queries = [
-            "BinaryPackageBuild.package_build = PackageBuild.id AND "
-            "PackageBuild.build_farm_job = BuildFarmJob.id AND "
             "DistroArchSeries.id = BinaryPackageBuild.distro_arch_series AND "
-            "PackageBuild.archive = %s AND "
+            "BinaryPackageBuild.archive = %s AND "
             "DistroArchSeries.architecturetag = %s AND "
             "BinaryPackageBuild.source_package_release = %s" % (
             sqlvalues(archive.id, distroarchseries.architecturetag, self))]
@@ -467,7 +459,7 @@
 
         return BinaryPackageBuild.selectFirst(
             query, clauseTables=clause_tables,
-            orderBy=['-BuildFarmJob.date_created'])
+            orderBy=['-date_created'])
 
     def override(self, component=None, section=None, urgency=None):
         """See ISourcePackageRelease."""

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2012-10-25 11:02:37 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2013-02-01 02:30:31 +0000
@@ -359,16 +359,13 @@
         # Return the count for archive build jobs with the given status.
         query = """
             SELECT COUNT(Job.id)
-            FROM BinaryPackageBuild, BuildPackageJob, BuildQueue, Job,
-                 PackageBuild, BuildFarmJob
+            FROM BinaryPackageBuild, BuildPackageJob, BuildQueue, Job
             WHERE
                 BuildPackageJob.build = BinaryPackageBuild.id
                 AND BuildPackageJob.job = BuildQueue.job
                 AND Job.id = BuildQueue.job
-                AND BinaryPackageBuild.package_build = PackageBuild.id
-                AND PackageBuild.archive = %s
-                AND PackageBuild.build_farm_job = BuildFarmJob.id
-                AND BuildFarmJob.status = %s
+                AND BinaryPackageBuild.archive = %s
+                AND BinaryPackageBuild.status = %s
                 AND Job.status = %s;
         """ % sqlvalues(archive, BuildStatus.NEEDSBUILD, status)
 

=== modified file 'lib/lp/translations/interfaces/translationtemplatesbuild.py'
--- lib/lp/translations/interfaces/translationtemplatesbuild.py	2011-12-24 16:54:44 +0000
+++ lib/lp/translations/interfaces/translationtemplatesbuild.py	2013-02-01 02:30:31 +0000
@@ -22,10 +22,6 @@
 class ITranslationTemplatesBuild(IBuildFarmJob):
     """The build information for translation templates builds."""
 
-    build_farm_job = Reference(
-        title=_("The build farm job that this extends."),
-        required=True, readonly=True, schema=IBuildFarmJob)
-
     branch = Reference(
         title=_("The branch that this build operates on."),
         required=True, readonly=True, schema=IBranch)
@@ -34,7 +30,7 @@
 class ITranslationTemplatesBuildSource(ISpecificBuildFarmJobSource):
     """Utility for `ITranslationTemplatesBuild`."""
 
-    def create(build_farm_job, branch):
+    def create(branch):
         """Create a new `ITranslationTemplatesBuild`."""
 
     def findByBranch(branch, store=None):

=== modified file 'lib/lp/translations/model/translationtemplatesbuild.py'
--- lib/lp/translations/model/translationtemplatesbuild.py	2013-02-01 02:30:31 +0000
+++ lib/lp/translations/model/translationtemplatesbuild.py	2013-02-01 02:30:31 +0000
@@ -57,6 +57,8 @@
 
     __storm_table__ = 'TranslationTemplatesBuild'
 
+    job_type = BuildFarmJobType.TRANSLATIONTEMPLATESBUILD
+
     id = Int(name='id', primary=True)
     build_farm_job_id = Int(name='build_farm_job', allow_none=False)
     build_farm_job = Reference(build_farm_job_id, 'BuildFarmJob.id')