]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Sync FK constraints in db models with migration scripts
authorJakub Libosvar <libosvar@redhat.com>
Thu, 20 Aug 2015 12:33:59 +0000 (12:33 +0000)
committerJakub Libosvar <libosvar@redhat.com>
Thu, 20 Aug 2015 13:22:01 +0000 (13:22 +0000)
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

neutron/db/l3_dvrscheduler_db.py
neutron/db/migration/alembic_migrations/versions/HEADS
neutron/db/migration/alembic_migrations/versions/liberty/contract/2e5352a0ad4d_add_missing_foreign_keys.py [new file with mode: 0644]
neutron/db/models_v2.py

index 5e937611a5213d6d64317af33cb56101594a5baa..fa7caaec2e42a5abb38cf84e3d8ed6f6aadb0ea4 100644 (file)
@@ -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)
 
index c4140b06d89860419b566595dd42422dff17cd4e..ce87f3775956ccca0bfc5a646f20547d4035b4fc 100644 (file)
@@ -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 (file)
index 0000000..322f6b0
--- /dev/null
@@ -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)
index 5a8b8311ebaab904253cecf0833e3c3e840f8a72..361d172cd624eedd681c3c65daebf2c097c25e16 100644 (file)
@@ -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)