def downgrade(active_plugins=None, options=None):
--- 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
-@@ -55,6 +55,46 @@
+@@ -55,19 +55,63 @@
"UPDATE ml2_port_bindings SET"
" vif_details = '{\"port_filter\": false}'"
" WHERE cap_port_filter = 0")
-+
-+ if op.get_bind().engine.name == 'sqlite':
-+ op.execute("CREATE TEMPORARY TABLE ml2_port_bindings_backup ( "
-+ "port_id VARCHAR(36) NOT NULL, "
-+ "host VARCHAR(255) NOT NULL, "
-+ "vif_type VARCHAR(64) NOT NULL, "
-+ "cap_port_filter BOOLEAN NOT NULL, "
-+ "driver VARCHAR(64), "
-+ "segment VARCHAR(36), "
-+ "vnic_type VARCHAR(64) DEFAULT 'normal' NOT NULL, "
-+ "vif_details VARCHAR(4095) DEFAULT '' NOT NULL, "
-+ "PRIMARY KEY (port_id), "
-+ "FOREIGN KEY(port_id) REFERENCES ports (id) ON DELETE CASCADE, "
-+ "FOREIGN KEY(segment) REFERENCES ml2_network_segments (id) ON DELETE SET NULL, "
-+ "CHECK (cap_port_filter IN (0, 1)));")
-+ op.execute("INSERT INTO ml2_port_bindings_backup "
-+ "(port_id,host,vif_type,cap_port_filter,driver,segment,vnic_type) "
-+ "SELECT port_id,host,vif_type,cap_port_filter,driver,segment,vnic_type "
-+ "FROM ml2_port_bindings;")
-+ for value in ('true', 'false'):
-+ op.execute("UPDATE ml2_port_bindings_backup SET"
-+ " vif_details = '{\"port_filter\": %(value)s}'"
-+ " WHERE cap_port_filter = '%(value)s'" % {'value': value})
-+ op.execute("DROP TABLE ml2_port_bindings")
-+ op.execute("CREATE TABLE ml2_port_bindings ( "
-+ "port_id VARCHAR(36) NOT NULL, "
-+ "host VARCHAR(255) NOT NULL, "
-+ "vif_type VARCHAR(64) NOT NULL, "
-+ "driver VARCHAR(64), "
-+ "segment VARCHAR(36), "
-+ "vnic_type VARCHAR(64) DEFAULT 'normal' NOT NULL, "
-+ "vif_details VARCHAR(4095) DEFAULT '' NOT NULL, "
-+ "PRIMARY KEY (port_id), "
-+ "FOREIGN KEY(port_id) REFERENCES ports (id) ON DELETE CASCADE, "
-+ "FOREIGN KEY(segment) REFERENCES ml2_network_segments (id) ON DELETE SET NULL);")
-+ op.execute("INSERT INTO ml2_port_bindings "
-+ "SELECT port_id,host,vif_type,driver,segment,vnic_type,vif_details "
-+ "FROM ml2_port_bindings_backup;")
-+ op.execute("DROP TABLE ml2_port_bindings_backup")
+
else:
- op.execute(
- "UPDATE ml2_port_bindings SET"
+- op.execute(
+- "UPDATE ml2_port_bindings SET"
+- " vif_details = '{\"port_filter\": true}'"
+- " WHERE cap_port_filter = true")
+- op.execute(
+- "UPDATE ml2_port_bindings SET"
+- " vif_details = '{\"port_filter\": false}'"
+- " WHERE cap_port_filter = false")
+- op.drop_column('ml2_port_bindings', 'cap_port_filter')
++ if op.get_bind().engine.name == 'sqlite':
++ op.execute("CREATE TEMPORARY TABLE ml2_port_bindings_backup ( "
++ "port_id VARCHAR(36) NOT NULL, "
++ "host VARCHAR(255) NOT NULL, "
++ "vif_type VARCHAR(64) NOT NULL, "
++ "cap_port_filter BOOLEAN NOT NULL, "
++ "driver VARCHAR(64), "
++ "segment VARCHAR(36), "
++ "vnic_type VARCHAR(64) DEFAULT 'normal' NOT NULL, "
++ "vif_details VARCHAR(4095) DEFAULT '' NOT NULL, "
++ "PRIMARY KEY (port_id), "
++ "FOREIGN KEY(port_id) REFERENCES ports (id) ON DELETE CASCADE, "
++ "FOREIGN KEY(segment) REFERENCES ml2_network_segments (id) ON DELETE SET NULL, "
++ "CHECK (cap_port_filter IN (0, 1)));")
++ op.execute("INSERT INTO ml2_port_bindings_backup "
++ "(port_id,host,vif_type,cap_port_filter,driver,segment,vnic_type) "
++ "SELECT port_id,host,vif_type,cap_port_filter,driver,segment,vnic_type "
++ "FROM ml2_port_bindings;")
++ for value in ('true', 'false'):
++ op.execute("UPDATE ml2_port_bindings_backup SET"
++ " vif_details = '{\"port_filter\": %(value)s}'"
++ " WHERE cap_port_filter = '%(value)s'" % {'value': value})
++ op.execute("DROP TABLE ml2_port_bindings")
++ op.execute("CREATE TABLE ml2_port_bindings ( "
++ "port_id VARCHAR(36) NOT NULL, "
++ "host VARCHAR(255) NOT NULL, "
++ "vif_type VARCHAR(64) NOT NULL, "
++ "driver VARCHAR(64), "
++ "segment VARCHAR(36), "
++ "vnic_type VARCHAR(64) DEFAULT 'normal' NOT NULL, "
++ "vif_details VARCHAR(4095) DEFAULT '' NOT NULL, "
++ "PRIMARY KEY (port_id), "
++ "FOREIGN KEY(port_id) REFERENCES ports (id) ON DELETE CASCADE, "
++ "FOREIGN KEY(segment) REFERENCES ml2_network_segments (id) ON DELETE SET NULL);")
++ op.execute("INSERT INTO ml2_port_bindings "
++ "SELECT port_id,host,vif_type,driver,segment,vnic_type,vif_details "
++ "FROM ml2_port_bindings_backup;")
++ op.execute("DROP TABLE ml2_port_bindings_backup")
++ else:
++
++ op.execute(
++ "UPDATE ml2_port_bindings SET"
++ " vif_details = '{\"port_filter\": true}'"
++ " WHERE cap_port_filter = true")
++ op.execute(
++ "UPDATE ml2_port_bindings SET"
++ " vif_details = '{\"port_filter\": false}'"
++ " WHERE cap_port_filter = false")
++ op.drop_column('ml2_port_bindings', 'cap_port_filter')
++
+ if op.get_bind().engine.name == 'ibm_db_sa':
+ op.execute("CALL SYSPROC.ADMIN_CMD('REORG TABLE ml2_port_bindings')")
+
++
++
+
+ def downgrade(active_plugins=None, options=None):
+ if not migration.should_run(active_plugins, migration_for_plugins):
--- a/neutron/db/migration/alembic_migrations/versions/e197124d4b9_add_unique_constrain.py
+++ b/neutron/db/migration/alembic_migrations/versions/e197124d4b9_add_unique_constrain.py
@@ -47,11 +47,17 @@