Ensure L to M DB migrations correctly inspect current DB state

During 082_unique_ns_record, we check if a uniqueconstraint exists
before adding it. However, the method used to check does not include
uniqueconstraints, resulting in a failure to execute the migration.

Change-Id: I26dc83bca913a7c63945b1e0d4d963f20854e989
Closes-Bug: 1583198
This commit is contained in:
Kiall Mac Innes
2016-05-18 15:37:20 +01:00
parent 961d1d8fac
commit 63d1c30803

View File

@@ -23,6 +23,7 @@ from migrate.changeset.constraint import UniqueConstraint
from oslo_log import log as logging
from sqlalchemy.schema import MetaData, Table
from sqlalchemy import exc
from sqlalchemy.engine.reflection import Inspector
LOG = logging.getLogger()
@@ -44,9 +45,11 @@ def upgrade(migrate_engine):
pool_ns_records_table = Table('pool_ns_records', meta, autoload=True)
# Only apply it if it's not there (It's been backported to L)
constraints = [i.name for i in pool_ns_records_table.constraints]
insp = Inspector.from_engine(migrate_engine)
unique_constraints = insp.get_unique_constraints('pool_ns_records')
unique_constraint_names = [i['name'] for i in unique_constraints]
if CONSTRAINT_NAME not in constraints:
if CONSTRAINT_NAME not in unique_constraint_names:
# We define the constraint here if not it shows in the list above.
constraint = UniqueConstraint('pool_id', 'hostname',
name=CONSTRAINT_NAME,