Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unique constraint for security groups
- Add unique constraint (project_id, name, deleted) for security_groups - Define new SecurityGroupExists exception - Drop security_group_exists() in favor of catching SecurityGroupExists exception for security_group_create() Fixes bug #1093458 Blueprint: db-enforce-unique-keys Change-Id: Id9a1427587cc9250942d0abd9eafc69861352d9b
- Loading branch information
Roman Bogorodskiy
committed
Jul 2, 2013
1 parent
88531ad
commit 231c970
Showing
9 changed files
with
125 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
nova/db/sqlalchemy/migrate_repo/versions/190_add_security_group_uc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Copyright (c) 2013 Boris Pavlovic (boris@pavlovic.me). | ||
# All Rights Reserved. | ||
# | ||
# 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. | ||
|
||
from migrate.changeset import UniqueConstraint | ||
from sqlalchemy import MetaData, Table | ||
|
||
from nova.db.sqlalchemy import utils | ||
|
||
|
||
UC_NAME = "uniq_security_groups0project_id0name0deleted" | ||
COLUMNS = ('project_id', 'name', 'deleted') | ||
TABLE_NAME = 'security_groups' | ||
|
||
|
||
def upgrade(migrate_engine): | ||
meta = MetaData(bind=migrate_engine) | ||
t = Table(TABLE_NAME, meta, autoload=True) | ||
|
||
utils.drop_old_duplicate_entries_from_table(migrate_engine, TABLE_NAME, | ||
True, *COLUMNS) | ||
uc = UniqueConstraint(*COLUMNS, table=t, name=UC_NAME) | ||
uc.create() | ||
|
||
|
||
def downgrade(migrate_engine): | ||
utils.drop_unique_constraint(migrate_engine, TABLE_NAME, UC_NAME, *COLUMNS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters