← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~danilo/launchpad/bugs-subscription into lp:launchpad/db-devel

 

Данило Шеган has proposed merging lp:~danilo/launchpad/bugs-subscription into lp:launchpad/db-devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~danilo/launchpad/bugs-subscription/+merge/46706

= Migrate StructuralSubscription to Storm: step 1 =

Migrate column definitions to Storm syntax.

== Implementation details ==

Used https://dev.launchpad.net/StormMigrationGuide as a guide.

I didn't use the default_factory=datetime.utcnow() (as suggested by bigjools on the wiki page, but nowhere to be found in our code), but instead have passed in tzinfo for DateTime columns (replacing UtcDateTimeCol).

== Tests ==

bin/test -ct bugsubscription.txt -t bugnotification-sending.txt -t structural-subscriptions.txt

== Demo and Q/A ==

Generally, if no tests fail, we feel this is safe.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/model/structuralsubscription.py
-- 
https://code.launchpad.net/~danilo/launchpad/bugs-subscription/+merge/46706
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/launchpad/bugs-subscription into lp:launchpad/db-devel.
=== modified file 'lib/lp/registry/model/structuralsubscription.py'
--- lib/lp/registry/model/structuralsubscription.py	2010-12-21 09:31:38 +0000
+++ lib/lp/registry/model/structuralsubscription.py	2011-01-18 23:01:46 +0000
@@ -7,7 +7,14 @@
     'StructuralSubscriptionTargetMixin',
     ]
 
-from sqlobject import ForeignKey
+import pytz
+
+from storm.locals import (
+    DateTime,
+    Int,
+    Reference,
+    )
+
 from storm.expr import (
     Alias,
     And,
@@ -31,8 +38,7 @@
 from zope.interface import implements
 
 from canonical.database.constants import UTC_NOW
-from canonical.database.datetimecol import UtcDateTimeCol
-from canonical.database.enumcol import EnumCol
+from canonical.database.enumcol import DBEnum
 from canonical.database.sqlbase import (
     quote,
     SQLBase,
@@ -81,44 +87,53 @@
 
     _table = 'StructuralSubscription'
 
-    product = ForeignKey(
-        dbName='product', foreignKey='Product', notNull=False, default=None)
-    productseries = ForeignKey(
-        dbName='productseries', foreignKey='ProductSeries', notNull=False,
-        default=None)
-    project = ForeignKey(
-        dbName='project', foreignKey='ProjectGroup', notNull=False,
-        default=None)
-    milestone = ForeignKey(
-        dbName='milestone', foreignKey='Milestone', notNull=False,
-        default=None)
-    distribution = ForeignKey(
-        dbName='distribution', foreignKey='Distribution', notNull=False,
-        default=None)
-    distroseries = ForeignKey(
-        dbName='distroseries', foreignKey='DistroSeries', notNull=False,
-        default=None)
-    sourcepackagename = ForeignKey(
-        dbName='sourcepackagename', foreignKey='SourcePackageName',
-        notNull=False, default=None)
-    subscriber = ForeignKey(
-        dbName='subscriber', foreignKey='Person',
-        storm_validator=validate_person, notNull=True)
-    subscribed_by = ForeignKey(
-        dbName='subscribed_by', foreignKey='Person',
-        storm_validator=validate_public_person, notNull=True)
-    bug_notification_level = EnumCol(
+    __storm_table__ = 'StructuralSubscription'
+
+    id = Int(primary=True)
+
+    productID = Int("product", default=None)
+    product = Reference(productID, "Product.id")
+
+    productseriesID = Int("productseries", default=None)
+    productseries = Reference(productseriesID, "ProductSeries.id")
+
+    projectID = Int("project", default=None)
+    project = Reference(productID, "ProjectGroup.id")
+
+    milestoneID = Int("milestone", default=None)
+    milestone = Reference(milestoneID, "Milestone.id")
+
+    distributionID = Int("distribution", default=None)
+    distribution = Reference(distributionID, "Distribution.id")
+
+    distroseriesID = Int("distroseries", default=None)
+    distroseries = Reference(distroseriesID, "DistroSeries.id")
+
+    sourcepackagenameID = Int("sourcepackagename", default=None)
+    sourcepackagename = Reference(sourcepackagenameID, "SourcePackageName.id")
+
+    subscriberID = Int("subscriber", allow_none=False,
+                        validator=validate_person)
+    subscriber = Reference(subscriberID, "Person.id")
+
+    subscribed_byID = Int("subscribed_by", allow_none=False,
+                          validator=validate_public_person)
+    subscribed_by = Reference(subscribed_byID, "Person.id")
+
+    bug_notification_level = DBEnum(
         enum=BugNotificationLevel,
         default=BugNotificationLevel.NOTHING,
-        notNull=True)
-    blueprint_notification_level = EnumCol(
+        allow_none=False)
+    blueprint_notification_level = DBEnum(
         enum=BlueprintNotificationLevel,
         default=BlueprintNotificationLevel.NOTHING,
-        notNull=True)
-    date_created = UtcDateTimeCol(
-        dbName='date_created', notNull=True, default=UTC_NOW)
-    date_last_updated = UtcDateTimeCol(
-        dbName='date_last_updated', notNull=True, default=UTC_NOW)
+        allow_none=False)
+    date_created = DateTime(
+        "date_created", allow_none=False, default=UTC_NOW,
+        tzinfo=pytz.UTC)
+    date_last_updated = DateTime(
+        "date_last_updated", allow_none=False, default=UTC_NOW,
+        tzinfo=pytz.UTC)
 
     @property
     def target(self):