Fix downgrade in 002_quota_class.py for MySQL

Downgrade in the script 002_quota_class.py is failing for MySQL
because there is an attempt to delete the quota_classes table
while the reservations table still has a foreign key defined.
The foreign key causes the delete of the quota_classes table to fail.

This change is based upon commit 8328fc46d7
which makes a similar change to 018_add_qos_specs.py .

Change-Id: I81844a2da4fb3b831f1f9dead3634e82f54e559e
Closes-bug: 1265944
This commit is contained in:
Jay S. Bryant 2014-01-06 12:44:26 -06:00
parent 24d7e24413
commit 1babca0b8f
1 changed files with 17 additions and 0 deletions

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from migrate import ForeignKeyConstraint
from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
@ -109,6 +110,22 @@ def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
if migrate_engine.name == 'mysql':
# NOTE(jsbryant): MySQL Cannot drop the quota_usages table
# until the foreign key reservations_ibfk_1 is removed. We
# remove the foreign key first, and then we drop the table.
table = Table('reservations', meta, autoload=True)
ref_table = Table('reservations', meta, autoload=True)
params = {'columns': [table.c['usage_id']],
'refcolumns': [ref_table.c['id']],
'name': 'reservations_ibfk_1'}
try:
fkey = ForeignKeyConstraint(**params)
fkey.drop()
except Exception:
LOG.error(_("Dropping foreign key reservations_ibfk_1 failed."))
quota_classes = Table('quota_classes', meta, autoload=True)
try:
quota_classes.drop()