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
This commit is contained in:
Alan Meadows 2013-12-26 11:12:37 -08:00
parent f10e1db7a5
commit 8328fc46d7
1 changed files with 26 additions and 8 deletions

View 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)
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
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