Browse Source

Bugfix missing foreign key removal for mysql

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
tags/2014.1.b2
Alan Meadows 5 years ago
parent
commit
8328fc46d7
1 changed files with 24 additions and 6 deletions
  1. 24
    6
      cinder/db/sqlalchemy/migrate_repo/versions/018_add_qos_specs.py

+ 24
- 6
cinder/db/sqlalchemy/migrate_repo/versions/018_add_qos_specs.py View File

@@ -18,6 +18,7 @@
18 18
 
19 19
 from sqlalchemy import Boolean, Column, DateTime
20 20
 from sqlalchemy import ForeignKey, MetaData, String, Table
21
+from migrate import ForeignKeyConstraint
21 22
 
22 23
 from cinder.openstack.common import log as logging
23 24
 
@@ -69,17 +70,34 @@ def downgrade(migrate_engine):
69 70
 
70 71
     qos_specs = Table('quality_of_service_specs', meta, autoload=True)
71 72
 
72
-    try:
73
-        qos_specs.drop()
74
-
75
-    except Exception:
76
-        LOG.error(_("Dropping quality_of_service_specs table failed."))
77
-        raise
73
+    if migrate_engine.name == 'mysql':
74
+        # NOTE(alanmeadows): MySQL Cannot drop column qos_specs_id
75
+        # until the foreign key volumes_types_ibfk_1 is removed.  We
76
+        # remove the foreign key first, and then we drop the column.
77
+        table = Table('volume_types', meta, autoload=True)
78
+        ref_table = Table('volume_types', meta, autoload=True)
79
+        params = {'columns': [table.c['qos_specs_id']],
80
+                  'refcolumns': [ref_table.c['id']],
81
+                  'name': 'volume_types_ibfk_1'}
82
+
83
+        try:
84
+            fkey = ForeignKeyConstraint(**params)
85
+            fkey.drop()
86
+        except Exception:
87
+            LOG.error(_("Dropping foreign key volume_types_ibfk_1 failed"))
78 88
 
79 89
     volume_types = Table('volume_types', meta, autoload=True)
80 90
     qos_specs_id = Column('qos_specs_id', String(36))
91
+
81 92
     try:
82 93
         volume_types.drop_column(qos_specs_id)
83 94
     except Exception:
84 95
         LOG.error(_("Dropping qos_specs_id column failed."))
85 96
         raise
97
+
98
+    try:
99
+        qos_specs.drop()
100
+
101
+    except Exception:
102
+        LOG.error(_("Dropping quality_of_service_specs table failed."))
103
+        raise

Loading…
Cancel
Save