From d744c3936ef6afa4b985e2241be3555b63fb699f Mon Sep 17 00:00:00 2001 From: Toshiaki Takahashi Date: Thu, 9 Jul 2020 14:59:17 +0900 Subject: [PATCH] Fix: Remove wrong constraint in vnf_package_vnfd Currently, vnf_package_vnfd table has a following constraint in database created by tacker db migration. This is incorrect, so this patch remove the constraint. CONSTRAINT `CONSTRAINT_1` CHECK (`deleted` in (0,1)) This is created because `deleted` was boolean before. `deleted` is varchar(36) now, so db migration change its type by alter_column method. But this does not remove check constraint. This patch add drop_constraint to remove the constraint. Change-Id: I7a62ecf3eeec2f363d0f099bb46d3dec7948501a Closes-Bug: #1886622 Signed-off-by: Toshiaki Takahashi --- .../975e28392888_add_unique_key_vnf_package_vnfd.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tacker/db/migration/alembic_migrations/versions/975e28392888_add_unique_key_vnf_package_vnfd.py b/tacker/db/migration/alembic_migrations/versions/975e28392888_add_unique_key_vnf_package_vnfd.py index 9841c5369..9bdb58480 100644 --- a/tacker/db/migration/alembic_migrations/versions/975e28392888_add_unique_key_vnf_package_vnfd.py +++ b/tacker/db/migration/alembic_migrations/versions/975e28392888_add_unique_key_vnf_package_vnfd.py @@ -28,6 +28,7 @@ down_revision = 'abbef484b34c' from alembic import op # noqa: E402 import sqlalchemy as sa # noqa: E402 +from sqlalchemy.engine import reflection # noqa: E402 def _migrate_duplicate_vnf_package_vnfd_id(table): @@ -56,6 +57,17 @@ def _migrate_duplicate_vnf_package_vnfd_id(table): def upgrade(active_plugins=None, options=None): + check_constraints = (reflection.Inspector.from_engine(op.get_bind()) + .get_check_constraints('vnf_package_vnfd')) + for constraint in check_constraints: + if '`deleted`' in constraint['sqltext']: + op.drop_constraint( + constraint_name=constraint['name'], + table_name='vnf_package_vnfd', + type_="check" + ) + break + op.alter_column('vnf_package_vnfd', 'deleted', type_=sa.String(36), default="0")