Merge "Fix incorrect change of Enum type"

This commit is contained in:
Jenkins 2014-04-29 21:32:09 +00:00 committed by Gerrit Code Review
commit 103868ac9b
4 changed files with 50 additions and 24 deletions

View File

@ -14,6 +14,9 @@
#
# @author: Mark McClain, DreamHost
from alembic import op
import sqlalchemy as sa
OVS_PLUGIN = ('neutron.plugins.openvswitch.ovs_neutron_plugin'
'.OVSNeutronPluginV2')
CISCO_PLUGIN = 'neutron.plugins.cisco.network_plugin.PluginV2'
@ -27,3 +30,24 @@ def should_run(active_plugins, migrate_plugins):
OVS_PLUGIN in migrate_plugins):
migrate_plugins.append(CISCO_PLUGIN)
return set(active_plugins) & set(migrate_plugins)
def alter_enum(table, column, enum_type, nullable):
bind = op.get_bind()
engine = bind.engine
if engine.name == 'postgresql':
values = {'table': table,
'column': column,
'name': enum_type.name}
op.execute("ALTER TYPE %(name)s RENAME TO old_%(name)s" % values)
enum_type.create(bind, checkfirst=False)
op.execute("ALTER TABLE %(table)s RENAME COLUMN %(column)s TO "
"old_%(column)s" % values)
op.add_column(table, sa.Column(column, enum_type, nullable=nullable))
op.execute("UPDATE %(table)s SET %(column)s = "
"old_%(column)s::text::%(name)s" % values)
op.execute("ALTER TABLE %(table)s DROP COLUMN old_%(column)s" % values)
op.execute("DROP TYPE old_%(name)s" % values)
else:
op.alter_column(table, column, type_=enum_type,
existing_nullable=nullable)

View File

@ -42,6 +42,11 @@ import sqlalchemy as sa
from neutron.db import migration
new_type = sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',
name='nvp_network_bindings_binding_type')
old_type = sa.Enum('flat', 'vlan', 'stt', 'gre',
name='nvp_network_bindings_binding_type')
def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
@ -50,10 +55,8 @@ def upgrade(active_plugins=None, options=None):
name='phy_uuid',
existing_type=sa.String(36),
existing_nullable=True)
op.alter_column('nvp_network_bindings', 'binding_type',
type_=sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',
name='nvp_network_bindings_binding_type'),
existing_nullable=True)
migration.alter_enum('nvp_network_bindings', 'binding_type', new_type,
nullable=False)
def downgrade(active_plugins=None, options=None):
@ -63,7 +66,5 @@ def downgrade(active_plugins=None, options=None):
name='tz_uuid',
existing_type=sa.String(36),
existing_nullable=True)
op.alter_column('nvp_network_bindings', 'binding_type',
type_=sa.Enum('flat', 'vlan', 'stt', 'gre',
name='nvp_network_bindings_binding_type'),
existing_nullable=True)
migration.alter_enum('nvp_network_bindings', 'binding_type', old_type,
nullable=False)

View File

@ -30,27 +30,28 @@ migration_for_plugins = [
'neutron.plugins.cisco.network_plugin.PluginV2'
]
from alembic import op
import sqlalchemy as sa
from neutron.db import migration
new_type = sa.Enum('vlan', 'overlay', 'trunk', 'multi-segment',
name='vlan_type')
old_type = sa.Enum('vlan', 'vxlan', 'trunk', 'multi-segment',
name='vlan_type')
def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
op.alter_column('cisco_network_profiles', 'segment_type',
existing_type=sa.Enum('vlan', 'overlay', 'trunk',
'multi-segment'),
existing_nullable=False)
migration.alter_enum('cisco_network_profiles', 'segment_type', new_type,
nullable=False)
def downgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
op.alter_column('cisco_network_profiles', 'segment_type',
existing_type=sa.Enum('vlan', 'vxlan', 'trunk',
'multi-segment'),
existing_nullable=False)
migration.alter_enum('cisco_network_profiles', 'segment_type', old_type,
nullable=False)

View File

@ -35,6 +35,9 @@ import sqlalchemy as sa
from neutron.db import migration
new_type = sa.Enum('vlan', 'vxlan', 'trunk', 'multi-segment', name='vlan_type')
old_type = sa.Enum('vlan', 'vxlan', name='vlan_type')
def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
@ -60,10 +63,8 @@ def upgrade(active_plugins=None, options=None):
sa.PrimaryKeyConstraint('multi_segment_id', 'segment1_id',
'segment2_id')
)
op.alter_column('cisco_network_profiles', 'segment_type',
existing_type=sa.Enum('vlan', 'vxlan', 'trunk',
'multi-segment'),
existing_nullable=False)
migration.alter_enum('cisco_network_profiles', 'segment_type', new_type,
nullable=False)
op.add_column('cisco_network_profiles',
sa.Column('sub_type', sa.String(length=255), nullable=True))
@ -74,7 +75,6 @@ def downgrade(active_plugins=None, options=None):
op.drop_table('cisco_n1kv_trunk_segments')
op.drop_table('cisco_n1kv_multi_segments')
op.alter_column('cisco_network_profiles', 'segment_type',
existing_type=sa.Enum('vlan', 'vxlan'),
existing_nullable=False)
migration.alter_enum('cisco_network_profiles', 'segment_type', old_type,
nullable=False)
op.drop_column('cisco_network_profiles', 'sub_type')