]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix Enum usage in 589f9237ca0e_cisco_n1kv_ml2_driver_tables
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Tue, 9 Jun 2015 08:30:06 +0000 (11:30 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Thu, 11 Jun 2015 12:19:12 +0000 (15:19 +0300)
PostgreSQL is more sensitive with types than MySQL, it creates a
separate type when a Enum is created. In migration 589f9237ca0e
type profile_type is trying to be created, but the type with such
name was already created in havana_initial migration.

The solution for this is not to create type in 589f9237ca0e
migration when dialect is PostgreSQL and use already created.

Closes-bug: #1463301

Change-Id: I66e74d50cc70673de8635616076779cc20cde113

neutron/db/migration/alembic_migrations/versions/589f9237ca0e_cisco_n1kv_ml2_driver_tables.py

index 6c091ce5d273b4211af459d94c07c7c760ae480d..c1f4422bdda480e7bdec81adeaeda7d2b989aa58 100644 (file)
@@ -31,7 +31,6 @@ import sqlalchemy as sa
 
 network_profile_type = sa.Enum('vlan', 'vxlan',
                                name='network_profile_type')
-profile_type = sa.Enum('network', 'policy', name='profile_type')
 
 
 def upgrade():
@@ -103,7 +102,15 @@ def upgrade():
                                 ondelete='CASCADE'),
         sa.PrimaryKeyConstraint('physical_network', 'vlan_id')
     )
-
+    # Bugfix for 1463301: PostgreSQL creates type when Enum assigned to column,
+    # but type profile_type was already created in cisco_init_opts, so it needs
+    # to be reused. MySQL do not create type for Enums.
+    if op.get_context().dialect.name == 'postgresql':
+        profile_type = sa.dialects.postgresql.ENUM('network', 'policy',
+                                                   name='profile_type',
+                                                   create_type=False)
+    else:
+        profile_type = sa.Enum('network', 'policy', name='profile_type')
     op.create_table(
         'cisco_ml2_n1kv_profile_bindings',
         sa.Column('profile_type', profile_type, nullable=True),