Merge "Add index for reservations on (deleted, uuid)"
This commit is contained in:
commit
847cc0b476
@ -0,0 +1,28 @@
|
|||||||
|
# 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 oslo_db.sqlalchemy import utils
|
||||||
|
from sqlalchemy import MetaData
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(migrate_engine):
|
||||||
|
meta = MetaData()
|
||||||
|
meta.bind = migrate_engine
|
||||||
|
|
||||||
|
index_name = 'reservations_deleted_uuid_idx'
|
||||||
|
columns = ['deleted', 'uuid']
|
||||||
|
if utils.index_exists_on_columns(migrate_engine, 'reservations', columns):
|
||||||
|
return
|
||||||
|
|
||||||
|
utils.add_index(migrate_engine, 'reservations', index_name, columns)
|
@ -636,6 +636,8 @@ class Reservation(BASE, CinderBase):
|
|||||||
__tablename__ = 'reservations'
|
__tablename__ = 'reservations'
|
||||||
__table_args__ = (Index('reservations_deleted_expire_idx',
|
__table_args__ = (Index('reservations_deleted_expire_idx',
|
||||||
'deleted', 'expire'),
|
'deleted', 'expire'),
|
||||||
|
Index('reservations_deleted_uuid_idx',
|
||||||
|
'deleted', 'uuid'),
|
||||||
CinderBase.__table_args__)
|
CinderBase.__table_args__)
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
|
@ -360,6 +360,18 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
|||||||
self.assertIsInstance(services.c.uuid.type,
|
self.assertIsInstance(services.c.uuid.type,
|
||||||
self.VARCHAR_TYPE)
|
self.VARCHAR_TYPE)
|
||||||
|
|
||||||
|
def _check_113(self, engine, data):
|
||||||
|
"""Test that adding reservations index works correctly."""
|
||||||
|
reservations = db_utils.get_table(engine, 'reservations')
|
||||||
|
index_columns = []
|
||||||
|
for idx in reservations.indexes:
|
||||||
|
if idx.name == 'reservations_deleted_uuid_idx':
|
||||||
|
index_columns = idx.columns.keys()
|
||||||
|
break
|
||||||
|
|
||||||
|
self.assertEqual(sorted(['deleted', 'uuid']),
|
||||||
|
sorted(index_columns))
|
||||||
|
|
||||||
def test_walk_versions(self):
|
def test_walk_versions(self):
|
||||||
self.walk_versions(False, False)
|
self.walk_versions(False, False)
|
||||||
self.assert_each_foreign_key_is_part_of_an_index()
|
self.assert_each_foreign_key_is_part_of_an_index()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user