From 4e35808f94db8c17a20608e137e2940195821fac Mon Sep 17 00:00:00 2001 From: Sam Morrison Date: Mon, 2 Apr 2012 11:22:10 +1000 Subject: [PATCH] Fix db migration 12 * fix bug 976908 Change-Id: I0248f825396d08688238e6d2ef37c8fcb49e8c9d --- Authors | 1 + .../migrate_repo/versions/012_id_to_uuid.py | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Authors b/Authors index 8158c2a874..d9c9302486 100644 --- a/Authors +++ b/Authors @@ -52,6 +52,7 @@ Rick Clark Rick Harris Reynolds Chin Russell Bryant +Sam Morrison Soren Hansen Stuart McLaren Taku Fukushima diff --git a/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py b/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py index fe6bf867c9..8db18c14ba 100644 --- a/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py +++ b/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py @@ -225,18 +225,24 @@ def _get_table(table_name, metadata): def _get_foreign_keys(t_images, t_image_members, t_image_properties): """Retrieve and return foreign keys for members/properties tables.""" - image_members_fk_name = list(t_image_members.foreign_keys)[0].name - image_properties_fk_name = list(t_image_properties.foreign_keys)[0].name + foreign_keys = [] + if t_image_members.foreign_keys: + img_members_fk_name = list(t_image_members.foreign_keys)[0].name - fk1 = migrate.ForeignKeyConstraint([t_image_members.c.image_id], - [t_images.c.id], - name=image_members_fk_name) + fk1 = migrate.ForeignKeyConstraint([t_image_members.c.image_id], + [t_images.c.id], + name=img_members_fk_name) + foreign_keys.append(fk1) - fk2 = migrate.ForeignKeyConstraint([t_image_properties.c.image_id], - [t_images.c.id], - name=image_properties_fk_name) + if t_image_properties.foreign_keys: + img_properties_fk_name = list(t_image_properties.foreign_keys)[0].name - return fk1, fk2 + fk2 = migrate.ForeignKeyConstraint([t_image_properties.c.image_id], + [t_images.c.id], + name=img_properties_fk_name) + foreign_keys.append(fk2) + + return foreign_keys def _update_all_ids_to_uuids(t_images, t_image_members, t_image_properties):