add missing index for 'owner' column on images table.

Fixes bug 1214830

Change-Id: I13355cd53460188a5154aa3f50277c3e92335e28
This commit is contained in:
Venkatesh Sampath 2013-08-21 15:22:32 +05:30
parent 3df62be512
commit 677d1b0775
3 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,40 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Rackspace Hosting
# 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 sqlalchemy import MetaData, Table, Index
INDEX_NAME = 'owner_image_idx'
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
images = Table('images', meta, autoload=True)
index = Index(INDEX_NAME, images.c.owner)
index.create(migrate_engine)
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
images = Table('images', meta, autoload=True)
index = Index(INDEX_NAME, images.c.owner)
index.drop(migrate_engine)

View File

@ -109,7 +109,8 @@ class Image(BASE, ModelBase):
__tablename__ = 'images'
__table_args__ = (Index('checksum_image_idx', 'checksum'),
Index('ix_images_is_public', 'is_public'),
Index('ix_images_deleted', 'deleted'),)
Index('ix_images_deleted', 'deleted'),
Index('owner_image_idx', 'owner'),)
id = Column(String(36), primary_key=True, default=uuidutils.generate_uuid)
name = Column(String(255))

View File

@ -783,3 +783,27 @@ class TestMigrations(utils.BaseTestCase):
for idx in new_table.indexes]
self.assertIn((index, columns), index_data)
def _check_028(self, engine, data):
owner_index = "owner_image_idx"
columns = ["owner"]
images_table = get_table(engine, 'images')
index_data = [(idx.name, idx.columns.keys())
for idx in images_table.indexes
if idx.name == owner_index]
self.assertIn((owner_index, columns), index_data)
def _post_downgrade_028(self, engine):
owner_index = "owner_image_idx"
columns = ["owner"]
images_table = get_table(engine, 'images')
index_data = [(idx.name, idx.columns.keys())
for idx in images_table.indexes
if idx.name == owner_index]
self.assertNotIn((owner_index, columns), index_data)