Merge "Make migration 274 idempotent so it can be backported"
This commit is contained in:
commit
3ace2392a5
|
@ -13,8 +13,13 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy import MetaData, Table, Index
|
||||
|
||||
from nova.i18n import _LI
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
"""Change instances (project_id) index to cover (project_id, deleted)."""
|
||||
|
@ -26,9 +31,15 @@ def upgrade(migrate_engine):
|
|||
|
||||
instances = Table('instances', meta, autoload=True)
|
||||
|
||||
index = Index('instances_project_id_deleted_idx',
|
||||
instances.c.project_id, instances.c.deleted)
|
||||
index.create()
|
||||
for index in instances.indexes:
|
||||
if [c.name for c in index.columns] == ['project_id', 'deleted']:
|
||||
LOG.info(_LI('Skipped adding instances_project_id_deleted_idx '
|
||||
'because an equivalent index already exists.'))
|
||||
break
|
||||
else:
|
||||
index = Index('instances_project_id_deleted_idx',
|
||||
instances.c.project_id, instances.c.deleted)
|
||||
index.create()
|
||||
|
||||
for index in instances.indexes:
|
||||
if [c.name for c in index.columns] == ['project_id']:
|
||||
|
@ -42,8 +53,14 @@ def downgrade(migrate_engine):
|
|||
|
||||
instances = Table('instances', meta, autoload=True)
|
||||
|
||||
index = Index('project_id', instances.c.project_id)
|
||||
index.create()
|
||||
for index in instances.indexes:
|
||||
if [c.name for c in index.columns] == ['project_id']:
|
||||
LOG.info(_LI('Skipped adding instances_project_id_idx '
|
||||
'because an equivalent index already exists.'))
|
||||
break
|
||||
else:
|
||||
index = Index('project_id', instances.c.project_id)
|
||||
index.create()
|
||||
|
||||
for index in instances.indexes:
|
||||
if [c.name for c in index.columns] == ['project_id', 'deleted']:
|
||||
|
|
Loading…
Reference in New Issue