From: rossella Date: Tue, 23 Sep 2014 16:09:09 +0000 (+0000) Subject: Add unique constraints in IPAvailabilityRange X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=65b57625c24d86ce632d475e2ba743069ae1d797;p=openstack-build%2Fneutron-build.git Add unique constraints in IPAvailabilityRange first_ip, allocation_pool_id and last_ip, allocation_pool_id should be unique in the table. These constraints are essential to detect concurrent modifications of the IpAvailabilityRange table if the SELECT ... FOR UPDATE lock is removed Change-Id: Iaf2288c0b6bf27e93c03691073d7f505ef24fdd3 Closes-bug: #1373015 --- diff --git a/neutron/db/migration/alembic_migrations/versions/44621190bc02_add_uniqueconstraint_ipavailability_ranges.py b/neutron/db/migration/alembic_migrations/versions/44621190bc02_add_uniqueconstraint_ipavailability_ranges.py new file mode 100644 index 000000000..66b57c12e --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/44621190bc02_add_uniqueconstraint_ipavailability_ranges.py @@ -0,0 +1,61 @@ +# Copyright 2014 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. +# + +"""add_uniqueconstraint_ipavailability_ranges + +Revision ID: 44621190bc02 +Revises: juno +Create Date: 2014-09-23 15:14:15.051921 + +""" + +# revision identifiers, used by Alembic. +revision = '44621190bc02' +down_revision = 'juno' + +from alembic import op + + +TABLE_NAME = 'ipavailabilityranges' +UC_1_NAME = 'uniq_ipavailabilityranges0first_ip0allocation_pool_id' +UC_2_NAME = 'uniq_ipavailabilityranges0last_ip0allocation_pool_id' + + +def upgrade(): + op.create_unique_constraint( + name=UC_1_NAME, + source=TABLE_NAME, + local_cols=['first_ip', 'allocation_pool_id'] + ) + + op.create_unique_constraint( + name=UC_2_NAME, + source=TABLE_NAME, + local_cols=['last_ip', 'allocation_pool_id'] + ) + + +def downgrade(): + op.drop_constraint( + name=UC_1_NAME, + table_name=TABLE_NAME, + type_='unique' + ) + + op.drop_constraint( + name=UC_2_NAME, + table_name=TABLE_NAME, + type_='unique' + ) diff --git a/neutron/db/migration/alembic_migrations/versions/HEAD b/neutron/db/migration/alembic_migrations/versions/HEAD index 7a30775e9..8c20ac433 100644 --- a/neutron/db/migration/alembic_migrations/versions/HEAD +++ b/neutron/db/migration/alembic_migrations/versions/HEAD @@ -1 +1 @@ -juno +44621190bc02 diff --git a/neutron/db/models_v2.py b/neutron/db/models_v2.py index 53efc6692..d27c4750a 100644 --- a/neutron/db/models_v2.py +++ b/neutron/db/models_v2.py @@ -63,6 +63,13 @@ class IPAvailabilityRange(model_base.BASEV2): primary_key=True) first_ip = sa.Column(sa.String(64), nullable=False, primary_key=True) last_ip = sa.Column(sa.String(64), nullable=False, primary_key=True) + __table_args__ = ( + sa.UniqueConstraint( + first_ip, allocation_pool_id, + name='uniq_ipavailabilityranges0first_ip0allocation_pool_id'), + sa.UniqueConstraint( + last_ip, allocation_pool_id, + name='uniq_ipavailabilityranges0last_ip0allocation_pool_id')) def __repr__(self): return "%s - %s" % (self.first_ip, self.last_ip)