]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Bugfix missing foreign key removal for mysql
authorAlan Meadows <alan.meadows@gmail.com>
Thu, 26 Dec 2013 19:12:37 +0000 (11:12 -0800)
committerAlan Meadows <alan.meadows@gmail.com>
Thu, 26 Dec 2013 19:29:39 +0000 (11:29 -0800)
Downgrading the cinder schema fails when running 018_add_qos_specs.py
under MySQL. The upgrade path of this schema patch adds the foreign
key volume_types_ibfk_1 on table volume_types, and the downgrade does
not correspondingly remove it before attempting to drop the
qos_specs_id column.  This update removes the foreign key when
the engine is mysql prior to dropping the column.

Change-Id: Ibd3b35ad3b0bd41ad04ab7aeeb28c3ba7e5d255d
Closes-Bug: #1264360

cinder/db/sqlalchemy/migrate_repo/versions/018_add_qos_specs.py

index 76868bf6ca8530bb92e60e4bd34a0f7e0d725bdb..c95d25e37957b851487d8ed52bcf55d5f0ecc26d 100644 (file)
@@ -18,6 +18,7 @@
 
 from sqlalchemy import Boolean, Column, DateTime
 from sqlalchemy import ForeignKey, MetaData, String, Table
+from migrate import ForeignKeyConstraint
 
 from cinder.openstack.common import log as logging
 
@@ -69,17 +70,34 @@ def downgrade(migrate_engine):
 
     qos_specs = Table('quality_of_service_specs', meta, autoload=True)
 
-    try:
-        qos_specs.drop()
-
-    except Exception:
-        LOG.error(_("Dropping quality_of_service_specs table failed."))
-        raise
+    if migrate_engine.name == 'mysql':
+        # NOTE(alanmeadows): MySQL Cannot drop column qos_specs_id
+        # until the foreign key volumes_types_ibfk_1 is removed.  We
+        # remove the foreign key first, and then we drop the column.
+        table = Table('volume_types', meta, autoload=True)
+        ref_table = Table('volume_types', meta, autoload=True)
+        params = {'columns': [table.c['qos_specs_id']],
+                  'refcolumns': [ref_table.c['id']],
+                  'name': 'volume_types_ibfk_1'}
+
+        try:
+            fkey = ForeignKeyConstraint(**params)
+            fkey.drop()
+        except Exception:
+            LOG.error(_("Dropping foreign key volume_types_ibfk_1 failed"))
 
     volume_types = Table('volume_types', meta, autoload=True)
     qos_specs_id = Column('qos_specs_id', String(36))
+
     try:
         volume_types.drop_column(qos_specs_id)
     except Exception:
         LOG.error(_("Dropping qos_specs_id column failed."))
         raise
+
+    try:
+        qos_specs.drop()
+
+    except Exception:
+        LOG.error(_("Dropping quality_of_service_specs table failed."))
+        raise