Merge lp:~cjwatson/launchpad/packageset-score-rename-finish into lp:launchpad

Proposed by Colin Watson on 2012-06-13
Status: Merged
Approved by: William Grant on 2012-06-13
Approved revision: no longer in the source branch.
Merged at revision: 15413
Proposed branch: lp:~cjwatson/launchpad/packageset-score-rename-finish
Merge into: lp:launchpad
Diff against target: 95 lines (+3/-50)
2 files modified
lib/lp/soyuz/model/buildpackagejob.py (+2/-1)
lib/lp/soyuz/model/packageset.py (+1/-49)
To merge this branch: bzr merge lp:~cjwatson/launchpad/packageset-score-rename-finish
Reviewer Review Type Date Requested Status
William Grant code 2012-06-13 Approve on 2012-06-13
Review via email: mp+110046@code.launchpad.net

Commit Message

Remove compatibility with the old Packageset.score column.

Description of the Change

== Summary ==

Complete the renaming of Packageset.score to Packageset.relative_build_score (bug 1000570).

== Proposed fix ==

Now that https://code.launchpad.net/~cjwatson/launchpad/db-packageset-score-rename/+merge/108336 has been landed and rolled out, it's safe to reverse https://code.launchpad.net/~cjwatson/launchpad/packageset-score-rename-support/+merge/107981 and remove name= from the property declaration. The combination of r15343 and this patch (verified with combinediff) is simply:

- relative_build_score = Int(name="score", allow_none=False)
+ relative_build_score = Int(allow_none=False)

== Tests ==

bin/test -vvct TestBuildPackageJobScore -t TestBuildQueueManual

== Demo and Q/A ==

None needed.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/buildpackagejob.py'
2--- lib/lp/soyuz/model/buildpackagejob.py 2012-05-30 14:00:39 +0000
3+++ lib/lp/soyuz/model/buildpackagejob.py 2012-06-13 11:34:28 +0000
4@@ -40,6 +40,7 @@
5 )
6 from lp.soyuz.interfaces.packageset import IPackagesetSet
7 from lp.soyuz.model.buildfarmbuildjob import BuildFarmBuildJob
8+from lp.soyuz.model.packageset import Packageset
9
10
11 class BuildPackageJob(BuildFarmJobOldDerived, Storm):
12@@ -110,7 +111,7 @@
13 self.build.source_package_release.name,
14 distroseries=self.build.distro_series)
15 if not package_sets.is_empty():
16- score += max(ps.relative_build_score for ps in package_sets)
17+ score += package_sets.max(Packageset.relative_build_score)
18
19 # Calculates the build queue time component of the score.
20 right_now = datetime.now(pytz.timezone('UTC'))
21
22=== modified file 'lib/lp/soyuz/model/packageset.py'
23--- lib/lp/soyuz/model/packageset.py 2012-05-30 14:00:39 +0000
24+++ lib/lp/soyuz/model/packageset.py 2012-06-13 11:34:28 +0000
25@@ -14,7 +14,6 @@
26 Storm,
27 Unicode,
28 )
29-from storm.store import Store
30 from zope.component import getUtility
31 from zope.interface import implements
32
33@@ -29,8 +28,6 @@
34 IMasterStore,
35 IStore,
36 )
37-from lp.services.database.postgresql import table_has_column
38-from lp.services.database.sqlbase import cursor
39 from lp.services.helpers import ensure_unicode
40 from lp.soyuz.interfaces.packageset import (
41 DuplicatePackagesetName,
42@@ -73,52 +70,7 @@
43 packagesetgroup_id = Int(name='packagesetgroup', allow_none=False)
44 packagesetgroup = Reference(packagesetgroup_id, 'PackagesetGroup.id')
45
46- # Provide a manual property instead of declaring the column in Storm.
47- # This is to handle a transition period where we rename the 'score'
48- # column to 'relative_build_score'. During the transition period, the
49- # code needs to work with both column names.
50- #
51- # The approach taken here only works because we never use 'score' in a
52- # WHERE clause or anything like that.
53- #
54- # Once the database change has taken place, this property should be
55- # deleted, and replaced with a class variable declaration as follows:
56- #
57- # relative_build_score = Int(allow_none=False)
58-
59- def _get_relative_build_score_column_name(self):
60- """Get the name of the column containing a relative build score.
61-
62- Older versions of the database call it 'score'; newer ones call it
63- 'relative_build_score'.
64-
65- Works by interrogating PostgreSQL's own records.
66- """
67- # Chose this look-before-you-leap implementation so as to avoid
68- # invalidating the query by forcing a ProgrammingError.
69- cur = cursor()
70- if table_has_column(cur, "packageset", "score"):
71- return "score"
72- else:
73- return "relative_build_score"
74-
75- @property
76- def relative_build_score(self):
77- """See `IPackageset`."""
78- store = Store.of(self)
79- store.flush()
80- column = self._get_relative_build_score_column_name()
81- query = "SELECT %s FROM packageset WHERE id=%%s" % column
82- return store.execute(query, (self.id,)).get_one()[0]
83-
84- @relative_build_score.setter
85- def relative_build_score(self, score):
86- """See `IPackageset`."""
87- store = Store.of(self)
88- store.flush()
89- column = self._get_relative_build_score_column_name()
90- query = "UPDATE packageset SET %s=%%s WHERE id=%%s" % column
91- return store.execute(query, (int(score), self.id))
92+ relative_build_score = Int(allow_none=False)
93
94 def add(self, data):
95 """See `IPackageset`."""