From: Jakub Libosvar Date: Thu, 20 Aug 2015 12:33:59 +0000 (+0000) Subject: Sync FK constraints in db models with migration scripts X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fad17a2d8449f8a364f40896ee0efe8248dbffd3;p=openstack-build%2Fneutron-build.git Sync FK constraints in db models with migration scripts We do have a functional test that compares Neutron's db models with migration scripts. The comparison is based on alembic library that had a bug which is gonna be solved in the next release [1]. Once we start using newer alembic, functional test mentioned above will start failing due to models and scripts are not in sync. This patch adds needed constraints discovered by running functional test locally with dev version of alembic. Note: There is already a patch [2] that fixes QoS. [1] https://bitbucket.org/zzzeek/alembic/issues/317 [2] https://review.openstack.org/#/c/214215/ Change-Id: I0d0bddb05f543365d09e592bd81759534de49367 Closes-Bug: 1486936 --- diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py index 5e937611a..fa7caaec2 100644 --- a/neutron/db/l3_dvrscheduler_db.py +++ b/neutron/db/l3_dvrscheduler_db.py @@ -52,8 +52,8 @@ class CentralizedSnatL3AgentBinding(model_base.BASEV2): sa.ForeignKey("agents.id", ondelete='CASCADE'), primary_key=True) host_id = sa.Column(sa.String(255)) - csnat_gw_port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id')) - + csnat_gw_port_id = sa.Column(sa.String(36), + sa.ForeignKey('ports.id', ondelete='CASCADE')) l3_agent = orm.relationship(agents_db.Agent) csnat_gw_port = orm.relationship(models_v2.Port) diff --git a/neutron/db/migration/alembic_migrations/versions/HEADS b/neutron/db/migration/alembic_migrations/versions/HEADS index c4140b06d..ce87f3775 100644 --- a/neutron/db/migration/alembic_migrations/versions/HEADS +++ b/neutron/db/migration/alembic_migrations/versions/HEADS @@ -1,3 +1,3 @@ -2a16083502f3 +2e5352a0ad4d 9859ac9c136 kilo diff --git a/neutron/db/migration/alembic_migrations/versions/liberty/contract/2e5352a0ad4d_add_missing_foreign_keys.py b/neutron/db/migration/alembic_migrations/versions/liberty/contract/2e5352a0ad4d_add_missing_foreign_keys.py new file mode 100644 index 000000000..322f6b065 --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/liberty/contract/2e5352a0ad4d_add_missing_foreign_keys.py @@ -0,0 +1,41 @@ +# Copyright 2015 Red Hat, Inc. +# +# 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. +# + +"""Add missing foreign keys + +Revision ID: 2e5352a0ad4d +Revises: 2a16083502f3 +Create Date: 2015-08-20 12:43:09.110427 + +""" + +# revision identifiers, used by Alembic. +revision = '2e5352a0ad4d' +down_revision = '2a16083502f3' + +from alembic import op +from sqlalchemy.engine import reflection + +from neutron.db import migration + + +TABLE_NAME = 'flavorserviceprofilebindings' + + +def upgrade(): + inspector = reflection.Inspector.from_engine(op.get_bind()) + fk_constraints = inspector.get_foreign_keys(TABLE_NAME) + migration.remove_foreign_keys(TABLE_NAME, fk_constraints) + migration.create_foreign_keys(TABLE_NAME, fk_constraints) diff --git a/neutron/db/models_v2.py b/neutron/db/models_v2.py index 5a8b8311e..361d172cd 100644 --- a/neutron/db/models_v2.py +++ b/neutron/db/models_v2.py @@ -228,7 +228,8 @@ class SubnetPoolPrefix(model_base.BASEV2): cidr = sa.Column(sa.String(64), nullable=False, primary_key=True) subnetpool_id = sa.Column(sa.String(36), - sa.ForeignKey('subnetpools.id'), + sa.ForeignKey('subnetpools.id', + ondelete='CASCADE'), nullable=False, primary_key=True)