Fix drop index in version 022 DB upgrade script

After the namespace related patch, the version 22 of the database upgrade
script returns an error on PostgreSQL database indicating that the index
"name" does not exist on the table "workflow_definitions_v2". This patch
adds a check before executing the drop index operation.

Change-Id: I9a11f489b39c091d84bf7ff9c6689fa5e96c21ce
Closes-Bug: #1708296
This commit is contained in:
Winson Chan 2017-08-02 21:33:49 +00:00
parent 326da7b77a
commit 1f35e91d7b
1 changed files with 12 additions and 1 deletions

View File

@ -27,8 +27,10 @@ down_revision = '021'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.engine import reflection
from sqlalchemy.sql import table, column
# A simple model of the workflow definitions table with only the field needed
wf_def = table('workflow_definitions_v2', column('namespace'))
@ -60,7 +62,16 @@ def upgrade():
)
)
op.drop_index('name', table_name='workflow_definitions_v2')
inspect = reflection.Inspector.from_engine(op.get_bind())
unique_constraints = [
unique_constraint['name'] for unique_constraint in
inspect.get_unique_constraints('workflow_definitions_v2')
]
if 'name' in unique_constraints:
op.drop_index('name', table_name='workflow_definitions_v2')
op.create_unique_constraint(
None,
'workflow_definitions_v2',