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
This commit is contained in:
parent
df2a951eb3
commit
76d617bebf
@ -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'
|
||||||
|
)
|
@ -1 +1 @@
|
|||||||
juno
|
44621190bc02
|
||||||
|
@ -63,6 +63,13 @@ class IPAvailabilityRange(model_base.BASEV2):
|
|||||||
primary_key=True)
|
primary_key=True)
|
||||||
first_ip = sa.Column(sa.String(64), nullable=False, 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)
|
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):
|
def __repr__(self):
|
||||||
return "%s - %s" % (self.first_ip, self.last_ip)
|
return "%s - %s" % (self.first_ip, self.last_ip)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user