← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:soyuz-dbenum into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:soyuz-dbenum into launchpad:master.

Commit message:
lp.soyuz: Use DBEnum rather than EnumCol

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/412042

I dropped `unique=False` since it did nothing in Storm's SQLObject emulation anyway; in Launchpad we define constraints (unique or otherwise) in the SQL schema, not in Storm models.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:soyuz-dbenum into launchpad:master.
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index 6da89d1..fc5b9b0 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -103,7 +103,7 @@ from lp.services.database.bulk import (
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import (
     ISlaveStore,
     IStore,
@@ -298,11 +298,11 @@ class Archive(SQLBase):
     distribution = ForeignKey(
         foreignKey='Distribution', dbName='distribution', notNull=False)
 
-    purpose = EnumCol(
-        dbName='purpose', unique=False, notNull=True, schema=ArchivePurpose)
+    purpose = DBEnum(
+        name='purpose', allow_none=False, enum=ArchivePurpose)
 
-    status = EnumCol(
-        dbName="status", unique=False, notNull=True, schema=ArchiveStatus,
+    status = DBEnum(
+        name="status", allow_none=False, enum=ArchiveStatus,
         default=ArchiveStatus.ACTIVE)
 
     _enabled = BoolCol(dbName='enabled', notNull=True, default=True)
diff --git a/lib/lp/soyuz/model/archivejob.py b/lib/lp/soyuz/model/archivejob.py
index 6aac1e6..3dcaff2 100644
--- a/lib/lp/soyuz/model/archivejob.py
+++ b/lib/lp/soyuz/model/archivejob.py
@@ -18,7 +18,7 @@ from zope.interface import (
     )
 
 from lp.services.config import config
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import IMasterStore
 from lp.services.database.stormbase import StormBase
 from lp.services.job.model.job import (
@@ -54,7 +54,7 @@ class ArchiveJob(StormBase):
     archive_id = Int(name='archive')
     archive = Reference(archive_id, Archive.id)
 
-    job_type = EnumCol(enum=ArchiveJobType, notNull=True)
+    job_type = DBEnum(enum=ArchiveJobType, allow_none=False)
 
     metadata = JSON('json_data')
 
diff --git a/lib/lp/soyuz/model/binarypackagerelease.py b/lib/lp/soyuz/model/binarypackagerelease.py
index 0ba1681..0421e81 100644
--- a/lib/lp/soyuz/model/binarypackagerelease.py
+++ b/lib/lp/soyuz/model/binarypackagerelease.py
@@ -21,7 +21,7 @@ from zope.interface import implementer
 
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.sqlbase import SQLBase
 from lp.services.database.sqlobject import (
     BoolCol,
@@ -59,13 +59,13 @@ class BinaryPackageRelease(SQLBase):
     description = StringCol(dbName='description', notNull=True)
     build = ForeignKey(
         dbName='build', foreignKey='BinaryPackageBuild', notNull=True)
-    binpackageformat = EnumCol(dbName='binpackageformat', notNull=True,
-                               schema=BinaryPackageFormat)
+    binpackageformat = DBEnum(name='binpackageformat', allow_none=False,
+                              enum=BinaryPackageFormat)
     component = ForeignKey(dbName='component', foreignKey='Component',
                            notNull=True)
     section = ForeignKey(dbName='section', foreignKey='Section', notNull=True)
-    priority = EnumCol(dbName='priority', notNull=True,
-                       schema=PackagePublishingPriority)
+    priority = DBEnum(name='priority', allow_none=False,
+                      enum=PackagePublishingPriority)
     shlibdeps = StringCol(dbName='shlibdeps')
     depends = StringCol(dbName='depends')
     recommends = StringCol(dbName='recommends')
diff --git a/lib/lp/soyuz/model/distributionjob.py b/lib/lp/soyuz/model/distributionjob.py
index 91c4571..2fb9da3 100644
--- a/lib/lp/soyuz/model/distributionjob.py
+++ b/lib/lp/soyuz/model/distributionjob.py
@@ -18,7 +18,7 @@ from zope.interface import implementer
 from lp.app.errors import NotFoundError
 from lp.registry.model.distribution import Distribution
 from lp.registry.model.distroseries import DistroSeries
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import IStore
 from lp.services.database.stormbase import StormBase
 from lp.services.job.model.job import (
@@ -49,7 +49,7 @@ class DistributionJob(StormBase):
     distroseries_id = Int(name='distroseries')
     distroseries = Reference(distroseries_id, DistroSeries.id)
 
-    job_type = EnumCol(enum=DistributionJobType, notNull=True)
+    job_type = DBEnum(enum=DistributionJobType, allow_none=False)
 
     metadata = JSON('json_data')
 
diff --git a/lib/lp/soyuz/model/distroarchseries.py b/lib/lp/soyuz/model/distroarchseries.py
index e8eef7a..32e6525 100644
--- a/lib/lp/soyuz/model/distroarchseries.py
+++ b/lib/lp/soyuz/model/distroarchseries.py
@@ -25,7 +25,7 @@ from lp.registry.interfaces.person import validate_public_person
 from lp.registry.interfaces.pocket import PackagePublishingPocket
 from lp.services.database.constants import DEFAULT
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import IStore
 from lp.services.database.sqlbase import SQLBase
 from lp.services.database.sqlobject import (
@@ -380,12 +380,12 @@ class PocketChroot(SQLBase):
     distroarchseries = ForeignKey(
         dbName='distroarchseries', foreignKey='DistroArchSeries', notNull=True)
 
-    pocket = EnumCol(
-        schema=PackagePublishingPocket,
-        default=PackagePublishingPocket.RELEASE, notNull=True)
+    pocket = DBEnum(
+        enum=PackagePublishingPocket,
+        default=PackagePublishingPocket.RELEASE, allow_none=False)
 
     chroot = ForeignKey(dbName='chroot', foreignKey='LibraryFileAlias')
 
-    image_type = EnumCol(
-        schema=BuildBaseImageType, default=BuildBaseImageType.CHROOT,
-        notNull=True)
+    image_type = DBEnum(
+        enum=BuildBaseImageType, default=BuildBaseImageType.CHROOT,
+        allow_none=False)
diff --git a/lib/lp/soyuz/model/files.py b/lib/lp/soyuz/model/files.py
index c14b7cc..3c77c36 100644
--- a/lib/lp/soyuz/model/files.py
+++ b/lib/lp/soyuz/model/files.py
@@ -10,7 +10,7 @@ __all__ = [
 from zope.interface import implementer
 
 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.sqlbase import SQLBase
 from lp.services.database.sqlobject import ForeignKey
 from lp.soyuz.enums import BinaryPackageFileType
@@ -30,8 +30,7 @@ class BinaryPackageFile(SQLBase):
                                       notNull=True)
     libraryfile = ForeignKey(dbName='libraryfile',
                              foreignKey='LibraryFileAlias', notNull=True)
-    filetype = EnumCol(dbName='filetype',
-                       schema=BinaryPackageFileType)
+    filetype = DBEnum(name='filetype', enum=BinaryPackageFileType)
 
 
 class SourceFileMixin:
@@ -55,4 +54,4 @@ class SourcePackageReleaseFile(SourceFileMixin, SQLBase):
                                       dbName='sourcepackagerelease')
     libraryfile = ForeignKey(foreignKey='LibraryFileAlias',
                              dbName='libraryfile')
-    filetype = EnumCol(schema=SourcePackageFileType)
+    filetype = DBEnum(enum=SourcePackageFileType)
diff --git a/lib/lp/soyuz/model/packagecopyjob.py b/lib/lp/soyuz/model/packagecopyjob.py
index f9bea8b..f3a91a8 100644
--- a/lib/lp/soyuz/model/packagecopyjob.py
+++ b/lib/lp/soyuz/model/packagecopyjob.py
@@ -45,7 +45,7 @@ from lp.registry.model.distroseries import DistroSeries
 from lp.services.config import config
 from lp.services.database import bulk
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import (
     IMasterStore,
     IStore,
@@ -108,9 +108,9 @@ class PackageCopyJob(StormBase):
     target_distroseries = Reference(target_distroseries_id, DistroSeries.id)
 
     package_name = Unicode('package_name')
-    copy_policy = EnumCol(enum=PackageCopyPolicy)
+    copy_policy = DBEnum(enum=PackageCopyPolicy)
 
-    job_type = EnumCol(enum=PackageCopyJobType, notNull=True)
+    job_type = DBEnum(enum=PackageCopyJobType, allow_none=False)
 
     metadata = JSON('json_data')
 
diff --git a/lib/lp/soyuz/model/packagediff.py b/lib/lp/soyuz/model/packagediff.py
index 5b16c29..c9ad7a3 100644
--- a/lib/lp/soyuz/model/packagediff.py
+++ b/lib/lp/soyuz/model/packagediff.py
@@ -26,7 +26,7 @@ from lp.services.database.bulk import load
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import IStore
 from lp.services.database.sqlbase import (
     SQLBase,
@@ -141,8 +141,8 @@ class PackageDiff(SQLBase):
         dbName="diff_content", foreignKey='LibraryFileAlias',
         notNull=False, default=None)
 
-    status = EnumCol(
-        dbName='status', notNull=True, schema=PackageDiffStatus,
+    status = DBEnum(
+        name='status', allow_none=False, enum=PackageDiffStatus,
         default=PackageDiffStatus.PENDING)
 
     @property
diff --git a/lib/lp/soyuz/model/publishing.py b/lib/lp/soyuz/model/publishing.py
index ff4d2bb..442ca59 100644
--- a/lib/lp/soyuz/model/publishing.py
+++ b/lib/lp/soyuz/model/publishing.py
@@ -50,7 +50,7 @@ from lp.services.database import bulk
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import (
     IMasterStore,
     IStore,
@@ -245,7 +245,7 @@ class SourcePackagePublishingHistory(SQLBase, ArchivePublisherBase):
     distroseries = ForeignKey(foreignKey='DistroSeries', dbName='distroseries')
     component = ForeignKey(foreignKey='Component', dbName='component')
     section = ForeignKey(foreignKey='Section', dbName='section')
-    status = EnumCol(schema=PackagePublishingStatus)
+    status = DBEnum(enum=PackagePublishingStatus)
     scheduleddeletiondate = UtcDateTimeCol(default=None)
     datepublished = UtcDateTimeCol(default=None)
     datecreated = UtcDateTimeCol(default=UTC_NOW)
@@ -254,9 +254,9 @@ class SourcePackagePublishingHistory(SQLBase, ArchivePublisherBase):
                               dbName='supersededby', default=None)
     datemadepending = UtcDateTimeCol(default=None)
     dateremoved = UtcDateTimeCol(default=None)
-    pocket = EnumCol(dbName='pocket', schema=PackagePublishingPocket,
-                     default=PackagePublishingPocket.RELEASE,
-                     notNull=True)
+    pocket = DBEnum(name='pocket', enum=PackagePublishingPocket,
+                    default=PackagePublishingPocket.RELEASE,
+                    allow_none=False)
     archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=True)
     copied_from_archive = ForeignKey(
         dbName="copied_from_archive", foreignKey="Archive", notNull=False)
@@ -643,8 +643,8 @@ class BinaryPackagePublishingHistory(SQLBase, ArchivePublisherBase):
         foreignKey='DistroArchSeries', dbName='distroarchseries')
     component = ForeignKey(foreignKey='Component', dbName='component')
     section = ForeignKey(foreignKey='Section', dbName='section')
-    priority = EnumCol(dbName='priority', schema=PackagePublishingPriority)
-    status = EnumCol(dbName='status', schema=PackagePublishingStatus)
+    priority = DBEnum(name='priority', enum=PackagePublishingPriority)
+    status = DBEnum(name='status', enum=PackagePublishingStatus)
     phased_update_percentage = IntCol(
         dbName='phased_update_percentage', notNull=False, default=None)
     scheduleddeletiondate = UtcDateTimeCol(default=None)
@@ -658,7 +658,7 @@ class BinaryPackagePublishingHistory(SQLBase, ArchivePublisherBase):
         foreignKey='BinaryPackageBuild', dbName='supersededby', default=None)
     datemadepending = UtcDateTimeCol(default=None)
     dateremoved = UtcDateTimeCol(default=None)
-    pocket = EnumCol(dbName='pocket', schema=PackagePublishingPocket)
+    pocket = DBEnum(name='pocket', enum=PackagePublishingPocket)
     archive = ForeignKey(dbName="archive", foreignKey="Archive", notNull=True)
     copied_from_archive = ForeignKey(
         dbName="copied_from_archive", foreignKey="Archive", notNull=False)
diff --git a/lib/lp/soyuz/model/queue.py b/lib/lp/soyuz/model/queue.py
index c5ff4f0..314dc74 100644
--- a/lib/lp/soyuz/model/queue.py
+++ b/lib/lp/soyuz/model/queue.py
@@ -52,10 +52,7 @@ from lp.services.database.constants import (
     )
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import (
-    DBEnum,
-    EnumCol,
-    )
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import (
     IMasterStore,
     IStore,
@@ -169,18 +166,17 @@ class PackageUpload(SQLBase):
 
     _defaultOrder = ['id']
 
-    status = EnumCol(
-        dbName='status', unique=False, notNull=True,
-        default=PackageUploadStatus.NEW, schema=PackageUploadStatus,
-        storm_validator=validate_status)
+    status = DBEnum(
+        name='status', allow_none=False,
+        default=PackageUploadStatus.NEW, enum=PackageUploadStatus,
+        validator=validate_status)
 
     date_created = UtcDateTimeCol(notNull=False, default=UTC_NOW)
 
     distroseries = ForeignKey(dbName="distroseries", foreignKey='DistroSeries')
 
-    pocket = EnumCol(
-        dbName='pocket', unique=False, notNull=True,
-        schema=PackagePublishingPocket)
+    pocket = DBEnum(
+        name='pocket', allow_none=False, enum=PackagePublishingPocket)
 
     changes_file_id = Int(name='changesfile')
     changesfile = Reference(changes_file_id, 'LibraryFileAlias.id')
@@ -1421,9 +1417,8 @@ class PackageUploadCustom(SQLBase):
     packageupload = ForeignKey(
         dbName='packageupload', foreignKey='PackageUpload')
 
-    customformat = EnumCol(
-        dbName='customformat', unique=False, notNull=True,
-        schema=PackageUploadCustomFormat)
+    customformat = DBEnum(
+        name='customformat', allow_none=False, enum=PackageUploadCustomFormat)
 
     libraryfilealias = ForeignKey(
         dbName='libraryfilealias', foreignKey="LibraryFileAlias", notNull=True)
diff --git a/lib/lp/soyuz/model/reporting.py b/lib/lp/soyuz/model/reporting.py
index f72b5b4..64211b3 100644
--- a/lib/lp/soyuz/model/reporting.py
+++ b/lib/lp/soyuz/model/reporting.py
@@ -14,7 +14,7 @@ from storm.locals import (
 from storm.properties import DateTime
 from zope.interface import implementer
 
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.soyuz.enums import ArchivePurpose
 from lp.soyuz.interfaces.reporting import (
     ILatestPersonSourcePackageReleaseCache,
@@ -38,7 +38,7 @@ class LatestPersonSourcePackageReleaseCache(Storm):
     maintainer_id = Int(name='maintainer')
     upload_archive_id = Int(name='upload_archive')
     upload_archive = Reference(upload_archive_id, 'Archive.id')
-    archive_purpose = EnumCol(schema=ArchivePurpose)
+    archive_purpose = DBEnum(enum=ArchivePurpose)
     upload_distroseries_id = Int(name='upload_distroseries')
     upload_distroseries = Reference(upload_distroseries_id, 'DistroSeries.id')
     sourcepackagename_id = Int(name='sourcepackagename')
diff --git a/lib/lp/soyuz/model/sourcepackagerelease.py b/lib/lp/soyuz/model/sourcepackagerelease.py
index 2615be9..65c3479 100644
--- a/lib/lp/soyuz/model/sourcepackagerelease.py
+++ b/lib/lp/soyuz/model/sourcepackagerelease.py
@@ -42,7 +42,7 @@ from lp.registry.interfaces.sourcepackage import (
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.datetimecol import UtcDateTimeCol
 from lp.services.database.decoratedresultset import DecoratedResultSet
-from lp.services.database.enumcol import EnumCol
+from lp.services.database.enumcol import DBEnum
 from lp.services.database.sqlbase import (
     cursor,
     SQLBase,
@@ -92,8 +92,9 @@ class SourcePackageRelease(SQLBase):
     signing_key_owner_id = Int(name="signing_key_owner")
     signing_key_owner = Reference(signing_key_owner_id, 'Person.id')
     signing_key_fingerprint = Unicode()
-    urgency = EnumCol(dbName='urgency', schema=SourcePackageUrgency,
-        default=SourcePackageUrgency.LOW, notNull=True)
+    urgency = DBEnum(
+        name='urgency', enum=SourcePackageUrgency,
+        default=SourcePackageUrgency.LOW, allow_none=False)
     dateuploaded = UtcDateTimeCol(dbName='dateuploaded', notNull=True,
         default=UTC_NOW)
     dsc = StringCol(dbName='dsc')
@@ -107,8 +108,9 @@ class SourcePackageRelease(SQLBase):
     build_conflicts_indep = StringCol(dbName='build_conflicts_indep')
     architecturehintlist = StringCol(dbName='architecturehintlist')
     homepage = StringCol(dbName='homepage')
-    format = EnumCol(dbName='format', schema=SourcePackageType,
-        default=SourcePackageType.DPKG, notNull=True)
+    format = DBEnum(
+        name='format', enum=SourcePackageType,
+        default=SourcePackageType.DPKG, allow_none=False)
     upload_distroseries = ForeignKey(foreignKey='DistroSeries',
         dbName='upload_distroseries')
     upload_archive = ForeignKey(