summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-06-28 20:49:51 +0000
committerGerrit Code Review <review@openstack.org>2013-06-28 20:49:51 +0000
commita5b54f9bfb8cecf5674eee6a765ec7bb6bdb0b7c (patch)
tree9fd2af1cddc50ca4fc6e814ff090a38274cd6612
parent911c3156563c4e33bff3b4652b30c744f8b12de6 (diff)
parenteb1b5eaac61c8f8199d3d54c300c3730bdb4667a (diff)
Merge "check for constraint before dropping"
-rw-r--r--keystone/common/sql/migration_helpers.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/keystone/common/sql/migration_helpers.py b/keystone/common/sql/migration_helpers.py
index 6d735f5e..6823b6a7 100644
--- a/keystone/common/sql/migration_helpers.py
+++ b/keystone/common/sql/migration_helpers.py
@@ -23,12 +23,11 @@ import sqlalchemy
# Constraints. SQLAlchemy does not yet attempt to determine the name
# for the constraint, and instead attempts to deduce it from the column.
# This fails on MySQL.
-def get_fkey_constraint_name(table, column_name):
- fkeys = [fk for fk in table.constraints
+def get_constraints_names(table, column_name):
+ fkeys = [fk.name for fk in table.constraints
if (column_name in fk.columns and
isinstance(fk, sqlalchemy.ForeignKeyConstraint))]
- constraint_name = fkeys[0].name
- return constraint_name
+ return fkeys
# remove_constraints and add_constraints both accept a list of dictionaries
@@ -41,13 +40,14 @@ def get_fkey_constraint_name(table, column_name):
# for the constraint.
def remove_constraints(constraints):
for constraint_def in constraints:
- migrate.ForeignKeyConstraint(
- columns=[getattr(constraint_def['table'].c,
- constraint_def['fk_column'])],
- refcolumns=[constraint_def['ref_column']],
- name=(get_fkey_constraint_name
- (constraint_def['table'],
- constraint_def['fk_column']))).drop()
+ constraint_names = get_constraints_names(constraint_def['table'],
+ constraint_def['fk_column'])
+ for constraint_name in constraint_names:
+ migrate.ForeignKeyConstraint(
+ columns=[getattr(constraint_def['table'].c,
+ constraint_def['fk_column'])],
+ refcolumns=[constraint_def['ref_column']],
+ name=constraint_name).drop()
def add_constraints(constraints):