Merge "Fix incorrect change of Enum type"
This commit is contained in:
commit
103868ac9b
@ -14,6 +14,9 @@
|
|||||||
#
|
#
|
||||||
# @author: Mark McClain, DreamHost
|
# @author: Mark McClain, DreamHost
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
OVS_PLUGIN = ('neutron.plugins.openvswitch.ovs_neutron_plugin'
|
OVS_PLUGIN = ('neutron.plugins.openvswitch.ovs_neutron_plugin'
|
||||||
'.OVSNeutronPluginV2')
|
'.OVSNeutronPluginV2')
|
||||||
CISCO_PLUGIN = 'neutron.plugins.cisco.network_plugin.PluginV2'
|
CISCO_PLUGIN = 'neutron.plugins.cisco.network_plugin.PluginV2'
|
||||||
@ -27,3 +30,24 @@ def should_run(active_plugins, migrate_plugins):
|
|||||||
OVS_PLUGIN in migrate_plugins):
|
OVS_PLUGIN in migrate_plugins):
|
||||||
migrate_plugins.append(CISCO_PLUGIN)
|
migrate_plugins.append(CISCO_PLUGIN)
|
||||||
return set(active_plugins) & set(migrate_plugins)
|
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)
|
||||||
|
@ -42,6 +42,11 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
from neutron.db import migration
|
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):
|
def upgrade(active_plugins=None, options=None):
|
||||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
if not migration.should_run(active_plugins, migration_for_plugins):
|
||||||
@ -50,10 +55,8 @@ def upgrade(active_plugins=None, options=None):
|
|||||||
name='phy_uuid',
|
name='phy_uuid',
|
||||||
existing_type=sa.String(36),
|
existing_type=sa.String(36),
|
||||||
existing_nullable=True)
|
existing_nullable=True)
|
||||||
op.alter_column('nvp_network_bindings', 'binding_type',
|
migration.alter_enum('nvp_network_bindings', 'binding_type', new_type,
|
||||||
type_=sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',
|
nullable=False)
|
||||||
name='nvp_network_bindings_binding_type'),
|
|
||||||
existing_nullable=True)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade(active_plugins=None, options=None):
|
def downgrade(active_plugins=None, options=None):
|
||||||
@ -63,7 +66,5 @@ def downgrade(active_plugins=None, options=None):
|
|||||||
name='tz_uuid',
|
name='tz_uuid',
|
||||||
existing_type=sa.String(36),
|
existing_type=sa.String(36),
|
||||||
existing_nullable=True)
|
existing_nullable=True)
|
||||||
op.alter_column('nvp_network_bindings', 'binding_type',
|
migration.alter_enum('nvp_network_bindings', 'binding_type', old_type,
|
||||||
type_=sa.Enum('flat', 'vlan', 'stt', 'gre',
|
nullable=False)
|
||||||
name='nvp_network_bindings_binding_type'),
|
|
||||||
existing_nullable=True)
|
|
||||||
|
@ -30,27 +30,28 @@ migration_for_plugins = [
|
|||||||
'neutron.plugins.cisco.network_plugin.PluginV2'
|
'neutron.plugins.cisco.network_plugin.PluginV2'
|
||||||
]
|
]
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from neutron.db import migration
|
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):
|
def upgrade(active_plugins=None, options=None):
|
||||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
if not migration.should_run(active_plugins, migration_for_plugins):
|
||||||
return
|
return
|
||||||
|
|
||||||
op.alter_column('cisco_network_profiles', 'segment_type',
|
migration.alter_enum('cisco_network_profiles', 'segment_type', new_type,
|
||||||
existing_type=sa.Enum('vlan', 'overlay', 'trunk',
|
nullable=False)
|
||||||
'multi-segment'),
|
|
||||||
existing_nullable=False)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade(active_plugins=None, options=None):
|
def downgrade(active_plugins=None, options=None):
|
||||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
if not migration.should_run(active_plugins, migration_for_plugins):
|
||||||
return
|
return
|
||||||
|
|
||||||
op.alter_column('cisco_network_profiles', 'segment_type',
|
migration.alter_enum('cisco_network_profiles', 'segment_type', old_type,
|
||||||
existing_type=sa.Enum('vlan', 'vxlan', 'trunk',
|
nullable=False)
|
||||||
'multi-segment'),
|
|
||||||
existing_nullable=False)
|
|
||||||
|
@ -35,6 +35,9 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
from neutron.db import migration
|
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):
|
def upgrade(active_plugins=None, options=None):
|
||||||
if not migration.should_run(active_plugins, migration_for_plugins):
|
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',
|
sa.PrimaryKeyConstraint('multi_segment_id', 'segment1_id',
|
||||||
'segment2_id')
|
'segment2_id')
|
||||||
)
|
)
|
||||||
op.alter_column('cisco_network_profiles', 'segment_type',
|
migration.alter_enum('cisco_network_profiles', 'segment_type', new_type,
|
||||||
existing_type=sa.Enum('vlan', 'vxlan', 'trunk',
|
nullable=False)
|
||||||
'multi-segment'),
|
|
||||||
existing_nullable=False)
|
|
||||||
op.add_column('cisco_network_profiles',
|
op.add_column('cisco_network_profiles',
|
||||||
sa.Column('sub_type', sa.String(length=255), nullable=True))
|
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_trunk_segments')
|
||||||
op.drop_table('cisco_n1kv_multi_segments')
|
op.drop_table('cisco_n1kv_multi_segments')
|
||||||
op.alter_column('cisco_network_profiles', 'segment_type',
|
migration.alter_enum('cisco_network_profiles', 'segment_type', old_type,
|
||||||
existing_type=sa.Enum('vlan', 'vxlan'),
|
nullable=False)
|
||||||
existing_nullable=False)
|
|
||||||
op.drop_column('cisco_network_profiles', 'sub_type')
|
op.drop_column('cisco_network_profiles', 'sub_type')
|
||||||
|
Loading…
Reference in New Issue
Block a user