-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly create and delete Aggregates
* If deleted aggregate with same name exists, ignore it * When delete aggregate, delete metadata as well * Removes aggregates.name unique constraint Fix bug 1052479 Change-Id: I430e69367bdedbf65049a5142d137ab788763ae3 (cherry picked from commit 852dd4d5cf137c9ec04ad65f7225b86e7a0fdeda)
- Loading branch information
1 parent
f8f4522
commit 10d94ac
Showing
5 changed files
with
92 additions
and
7 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
48 changes: 48 additions & 0 deletions
48
nova/db/sqlalchemy/migrate_repo/versions/133_aggregate_delete_fix.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,48 @@ | ||
# Copyright 2012 OpenStack LLC. | ||
# | ||
# 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 sqlalchemy import String, Column, MetaData, Table | ||
from migrate.changeset import UniqueConstraint | ||
|
||
from nova.openstack.common import log as logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def upgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
dialect = migrate_engine.url.get_dialect().name | ||
|
||
aggregates = Table('aggregates', meta, autoload=True) | ||
if dialect.startswith('sqlite'): | ||
aggregates.c.name.alter(unique=False) | ||
elif dialect.startswith('postgres'): | ||
ucon = UniqueConstraint('name', | ||
name='aggregates_name_key', | ||
table=aggregates) | ||
ucon.drop() | ||
|
||
else: | ||
col2 = aggregates.c.name | ||
UniqueConstraint(col2, name='name').drop() | ||
|
||
|
||
def downgrade(migrate_engine): | ||
meta = MetaData() | ||
meta.bind = migrate_engine | ||
|
||
aggregates = Table('aggregates', meta, autoload=True) | ||
aggregates.c.name.alter(unique=True) |
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