From bbf268ff5401891015f0238ee39b27f69d46e836 Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Wed, 26 Mar 2014 09:42:21 +0100 Subject: [PATCH] Migrate data from cap_port_filter to vif_details There was introduced a new column vif_details for ml2_port_binding table and dropped cap_port_filter column. Data was lost during the migration causing no data in vif_details. This patch transforms data from cap_port_filter to vif_details column as a part of db migration. MigrationContext.execute() calls underlaying methods depending whether migration is online or offline therefore data are migrated in offline migration too. Partial-bug: #1235149 Change-Id: Icc5dc6e8221a542f5190d0222ac4d10197d15ac1 --- .../50d5ba354c23_ml2_binding_vif_details.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py b/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py index fc50807dac..b7de5fc9f0 100644 --- a/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py +++ b/neutron/db/migration/alembic_migrations/versions/50d5ba354c23_ml2_binding_vif_details.py @@ -33,6 +33,7 @@ migration_for_plugins = [ 'neutron.plugins.ml2.plugin.Ml2Plugin' ] +from alembic import context from alembic import op import sqlalchemy as sa @@ -46,6 +47,13 @@ def upgrade(active_plugins=None, options=None): op.add_column('ml2_port_bindings', sa.Column('vif_details', sa.String(length=4095), nullable=False, server_default='')) + migr_context = context.get_context() + with context.begin_transaction(): + for value in ('true', 'false'): + migr_context.execute( + "UPDATE ml2_port_bindings SET" + " vif_details = '{\"port_filter\": %(value)s}'" + " WHERE cap_port_filter = %(value)s" % {'value': value}) op.drop_column('ml2_port_bindings', 'cap_port_filter') @@ -55,5 +63,11 @@ def downgrade(active_plugins=None, options=None): op.add_column('ml2_port_bindings', sa.Column('cap_port_filter', sa.Boolean(), - nullable=False, server_default=False)) + nullable=False, default=False)) + migr_context = context.get_context() + with context.begin_transaction(): + migr_context.execute( + "UPDATE ml2_port_bindings SET" + " cap_port_filter = true" + " WHERE vif_details LIKE '%\"port_filter\": true%'") op.drop_column('ml2_port_bindings', 'vif_details')