# Copyright 2019 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Namespace support postgresql

Revision ID: 035
Revises: 034
Create Date: 2019-08-01 15:48:34.115639

"""

# revision identifiers, used by Alembic.
revision = '035'
down_revision = '034'

from alembic import op
from sqlalchemy.engine import reflection


def upgrade():

    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 'workflow_definitions_v2_name_project_id_key' in unique_constraints:
        op.drop_constraint('workflow_definitions_v2_name_project_id_key',
                           table_name='workflow_definitions_v2')
