From e62d0cb93a4ac788f208982d5d24ced4bc7c4c8f Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 26 Feb 2013 00:47:49 +0000 Subject: Migration 147: Prevent duplicate aggregate_hosts If an aggregate_host record is already present, then the `upgrade` shouldn't attempt to add it again. Change-Id: Ib7ab10fa7c166ccaa3df6a96eb08c7ebcd0af38c --- nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py index d93cd1ead..5c079584d 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py @@ -58,8 +58,12 @@ def upgrade(migrate_engine): }) # add host to zone agg_hosts = Table('aggregate_hosts', meta, autoload=True) - row = agg_hosts.insert() - row.execute({'host': rec['host'], 'aggregate_id': agg_id}) + num_hosts = agg_hosts.count().where( + agg_hosts.c.host == rec['host']).where( + agg_hosts.c.aggregate_id == agg_id).execute().scalar() + if num_hosts == 0: + agg_hosts.insert().execute({'host': rec['host'], + 'aggregate_id': agg_id}) services.drop_column('availability_zone') -- cgit