Add migration 20 - drop images.location

The image location data has been migrated out of this column, so it
is no longer useful. This migration simply drops it.

Related to bp multiple-image-locations

Change-Id: I5985c7ef41fceeb3d23063c7e9e76b3b9271ffa2
This commit is contained in:
Brian Waldon 2013-01-29 13:45:22 -08:00
parent fd9d069a6e
commit b0b380fb70
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 OpenStack Foundation
# 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.
import sqlalchemy
from glance.db.sqlalchemy.migrate_repo import schema
def get_images_table(meta):
return sqlalchemy.Table('images', meta, autoload=True)
def upgrade(migrate_engine):
meta = sqlalchemy.schema.MetaData(migrate_engine)
images_table = get_images_table(meta)
images_table.columns['location'].drop()
def downgrade(migrate_engine):
meta = sqlalchemy.schema.MetaData(migrate_engine)
images_table = get_images_table(meta)
location = sqlalchemy.Column('location', schema.Text())
location.create(images_table)

View File

@ -662,3 +662,23 @@ class TestMigrations(utils.BaseTestCase):
locations = dict([(i.id, i.location) for i in records])
self.assertEqual({'1': 'http://swift.example.com', '2': None},
locations)
def test_migration_20(self):
for key, engine in self.engines.items():
self.config(sql_connection=TestMigrations.TEST_DATABASES[key])
migration_api.version_control(version=0)
migration_api.upgrade(19)
images_table = Table('images', MetaData(engine), autoload=True)
self.assertTrue('location' in images_table.c)
migration_api.upgrade(20)
images_table = Table('images', MetaData(engine), autoload=True)
self.assertFalse('location' in images_table.c)
migration_api.downgrade(19)
images_table = Table('images', MetaData(engine), autoload=True)
self.assertTrue('location' in images_table.c)