From b0b380fb709f6977c18cbb4b1b277cf7cb04c1eb Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 29 Jan 2013 13:45:22 -0800 Subject: [PATCH] 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 --- .../020_drop_images_table_location.py | 37 +++++++++++++++++++ glance/tests/unit/test_migrations.py | 20 ++++++++++ 2 files changed, 57 insertions(+) create mode 100644 glance/db/sqlalchemy/migrate_repo/versions/020_drop_images_table_location.py diff --git a/glance/db/sqlalchemy/migrate_repo/versions/020_drop_images_table_location.py b/glance/db/sqlalchemy/migrate_repo/versions/020_drop_images_table_location.py new file mode 100644 index 0000000000..ace08a5ad0 --- /dev/null +++ b/glance/db/sqlalchemy/migrate_repo/versions/020_drop_images_table_location.py @@ -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) diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index cd7d351297..7e57d0a8ee 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -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)