~ubuntu-server-dev/glance/precise-essex

« back to all changes in this revision

Viewing changes to debian/patches/fix_migration_012_foreign_keys.patch

  • Committer: Chuck Short
  • Date: 2012-04-12 19:31:27 UTC
  • mfrom: (142.1.4 glance-proposed)
  • Revision ID: zulcss@ubuntu.com-20120412193127-in8n3qe079tymk95
* debian/patches/fix_migration_012_foreign_keys.patch: Fix a migration issue
  around missing FKs. Cherry-picked from upstream.  Can be dropped with
  first stable update.
* debian/patches/convert_properties_to_uuid.patch: Fixes migration 012 to
  also convert kernel_id and ramdisk_ids to UUID. Cherry picked from upstream.
  Can be dropped with first stable update (LP: #975651)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From: 4e35808f94db8c17a20608e137e2940195821fac
 
2
Author: Sam Morrison <sorrison@gmail.com>
 
3
Date:   Mon Apr 2 11:22:10 2012 +1000
 
4
Bug: https://bugs.launchpad.net/glance/+bug/976908
 
5
Origin, upstream: https://review.openstack.org/#change,6061
 
6
Bug: https://bugs.launchpad.net/glance/+bug/976908
 
7
Subject: Fix db migration 12
 
8
 
 
9
* fix bug 976908
 
10
 
 
11
Change-Id: I0248f825396d08688238e6d2ef37c8fcb49e8c9d
 
12
 
 
13
 
 
14
diff --git a/Authors b/Authors
 
15
index 8158c2a..d9c9302 100644
 
16
--- a/Authors
 
17
+++ b/Authors
 
18
@@ -52,6 +52,7 @@ Rick Clark <rick@openstack.org>
 
19
 Rick Harris <rconradharris@gmail.com>
 
20
 Reynolds Chin <benzwt@gmail.com>
 
21
 Russell Bryant <rbryant@redhat.com>
 
22
+Sam Morrison <sorrison@gmail.com>
 
23
 Soren Hansen <soren.hansen@rackspace.com>
 
24
 Stuart McLaren <stuart.mclaren@hp.com>
 
25
 Taku Fukushima <tfukushima@dcl.info.waseda.ac.jp>
 
26
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
 
27
index fe6bf86..8db18c1 100644
 
28
--- a/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py
 
29
+++ b/glance/registry/db/migrate_repo/versions/012_id_to_uuid.py
 
30
@@ -225,18 +225,24 @@ def _get_table(table_name, metadata):
 
31
 
 
32
 def _get_foreign_keys(t_images, t_image_members, t_image_properties):
 
33
     """Retrieve and return foreign keys for members/properties tables."""
 
34
-    image_members_fk_name = list(t_image_members.foreign_keys)[0].name
 
35
-    image_properties_fk_name = list(t_image_properties.foreign_keys)[0].name
 
36
+    foreign_keys = []
 
37
+    if t_image_members.foreign_keys:
 
38
+        img_members_fk_name = list(t_image_members.foreign_keys)[0].name
 
39
 
 
40
-    fk1 = migrate.ForeignKeyConstraint([t_image_members.c.image_id],
 
41
-                                       [t_images.c.id],
 
42
-                                       name=image_members_fk_name)
 
43
+        fk1 = migrate.ForeignKeyConstraint([t_image_members.c.image_id],
 
44
+                                           [t_images.c.id],
 
45
+                                           name=img_members_fk_name)
 
46
+        foreign_keys.append(fk1)
 
47
 
 
48
-    fk2 = migrate.ForeignKeyConstraint([t_image_properties.c.image_id],
 
49
-                                       [t_images.c.id],
 
50
-                                       name=image_properties_fk_name)
 
51
+    if t_image_properties.foreign_keys:
 
52
+        img_properties_fk_name = list(t_image_properties.foreign_keys)[0].name
 
53
 
 
54
-    return fk1, fk2
 
55
+        fk2 = migrate.ForeignKeyConstraint([t_image_properties.c.image_id],
 
56
+                                           [t_images.c.id],
 
57
+                                           name=img_properties_fk_name)
 
58
+        foreign_keys.append(fk2)
 
59
+
 
60
+    return foreign_keys
 
61
 
 
62
 
 
63
 def _update_all_ids_to_uuids(t_images, t_image_members, t_image_properties):