Fix aggregate_hosts.host migration for sqlite

* Make sure data is not lost during migration
* Changes migration 111_general_aggregates
* Adds test for change

Fix bug 1053131

Change-Id: Idbf0cbd5fdb7758ea1794019807d83d159270cba
(cherry picked from commit a5dbdb53da)
This commit is contained in:
Joe Gordon 2012-09-19 20:54:33 +00:00 committed by Vishvananda Ishaya
parent d23cac1a76
commit f8f45223de
2 changed files with 25 additions and 2 deletions

View File

@ -43,8 +43,7 @@ def upgrade(migrate_engine):
aggregate_hosts = Table('aggregate_hosts', meta, autoload=True)
if dialect.startswith('sqlite'):
aggregate_hosts.drop_column('host')
aggregate_hosts.create_column(Column('host', String(255)))
aggregate_hosts.c.host.alter(unique=False)
elif dialect.startswith('postgres'):
ucon = UniqueConstraint('host',
name='aggregate_hosts_host_key',

View File

@ -456,3 +456,27 @@ class TestMigrations(test.TestCase):
sm_vols = sqlalchemy.select([sm_volume.c.id]).execute().fetchall()
self.assertEqual(set([sm_vol.id for sm_vol in sm_vols]),
set([vol1_id]))
def test_migration_111(self):
for key, engine in self.engines.items():
migration_api.version_control(engine, TestMigrations.REPOSITORY,
migration.INIT_VERSION)
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 110)
metadata = sqlalchemy.schema.MetaData()
metadata.bind = engine
aggregate_hosts = sqlalchemy.Table('aggregate_hosts', metadata,
autoload=True)
host = 'host'
aggregate_hosts.insert().values(id=1,
aggregate_id=1, host=host).execute()
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 111)
agg = sqlalchemy.select([aggregate_hosts.c.host]).execute().first()
self.assertEqual(host, agg.host)
aggregate_hosts.insert().values(id=2,
aggregate_id=2, host=host).execute()
migration_api.downgrade(engine, TestMigrations.REPOSITORY, 111)
agg = sqlalchemy.select([aggregate_hosts.c.host]).execute().first()
self.assertEqual(host, agg.host)