Repository: fedora-infra/bodhi

Issue:
Create Enums for Containers
In order for Bodhi to support containers, we will need to add enums for them.


Discussion:

Resolving patch:
diff --git a/bodhi/server/migrations/versions/da710ff02641_add_container_enum.py b/bodhi/server/migrations/versions/da710ff02641_add_container_enum.py
new file mode 100644
--- /dev/null
+++ b/bodhi/server/migrations/versions/da710ff02641_add_container_enum.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2017 Red Hat, Inc.
+#
+# This file is part of Bodhi.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+"""
+Add container enum.
+
+Revision ID: da710ff02641
+Revises: 630acb5218a4
+Create Date: 2017-12-13 02:08:07.726789
+"""
+from alembic import op
+from sqlalchemy import exc
+
+
+# revision identifiers, used by Alembic.
+revision = 'da710ff02641'
+down_revision = '630acb5218a4'
+
+
+def upgrade():
+    """Add a 'container' content type enum value in ck_content_type."""
+    op.execute('COMMIT')  # See https://bitbucket.org/zzzeek/alembic/issue/123
+    try:
+        # This will raise a ProgrammingError if the DB server doesn't use BDR.
+        op.execute('SHOW bdr.permit_ddl_locking')
+        # This server uses BDR, so let's ask for a DDL lock.
+        op.execute('SET LOCAL bdr.permit_ddl_locking = true')
+    except exc.ProgrammingError:
+        # This server doesn't use BDR, so no problem.
+        pass
+    op.execute("ALTER TYPE ck_content_type ADD VALUE 'container' AFTER 'module'")
+
+
+def downgrade():
+    """
+    Alert user that we cannot downgrade this migration.
+
+    PostgreSQL does not allow enum values to be removed.
+    """
+    raise NotImplementedError("Downgrading this migration is not supported.")
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -522,11 +522,13 @@ class ContentType(DeclEnum):
             content types.
         rpm (EnumSymbol): Used to represent RPM related objects.
         module (EnumSymbol): Used to represent Module related objects.
+        container (EnumSymbol): Used to represent Container related objects.
     """
 
     base = 'base', 'Base'
     rpm = 'rpm', 'RPM'
     module = 'module', 'Module'
+    container = 'container', 'Container'
 
     @classmethod
     def infer_content_class(cls, base, build):
@@ -1142,6 +1144,14 @@ def __str__(self):
         return x
 
 
+class ContainerPackage(Package):
+    """Represents a Container package."""
+
+    __mapper_args__ = {
+        'polymorphic_identity': ContentType.container,
+    }
+
+
 class ModulePackage(Package):
     """Represents a Module package."""
 
@@ -1270,6 +1280,18 @@ def unpush(self, koji):
                 koji.moveBuild(tag, release.candidate_tag, self.nvr)
 
 
+class ContainerBuild(Build):
+    """
+    Represents a Container build.
+
+    Note that this model uses single-table inheritance with its Build superclass.
+    """
+
+    __mapper_args__ = {
+        'polymorphic_identity': ContentType.container,
+    }
+
+
 class ModuleBuild(Build):
     """
     Represents a Module build.


Test patch: