From a5dbdb53da470916248c8ef8715ef6e06dfa1d0f Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Wed, 19 Sep 2012 20:54:33 +0000 Subject: 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 --- .../versions/111_general_aggregates.py | 3 +-- nova/tests/test_migrations.py | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'nova') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py b/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py index 0c97112ce..df4a83843 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/111_general_aggregates.py @@ -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', diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py index 73b50c280..1e8714b94 100644 --- a/nova/tests/test_migrations.py +++ b/nova/tests/test_migrations.py @@ -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) -- cgit