Pull the indexes out of the dictionary directly
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 8 Aug 2014 16:39:44 +0000 (11:39 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 8 Aug 2014 16:39:44 +0000 (11:39 -0500)
Instead of checking for their keys and pulling them out later, that is.

mediagoblin/db/migrations.py

index fca7819bddadc736ca34eddc22eb60b38e8d072f..faf84c151f2832b8ca0b77978999d29528bd47c6 100644 (file)
@@ -839,8 +839,13 @@ def revert_username_index(db):
     user_table = inspect_table(metadata, "core__users")
     indexes = {index.name: index for index in user_table.indexes}
 
-    if not (u'ix_core__users_uploader' in indexes or
-            u'ix_core__users_username' in indexes):
+    # index from unnecessary migration
+    users_uploader_index = indexes.get(u'ix_core__users_uploader')
+    # index created from models.py after (unique=True, index=True)
+    # was set in models.py
+    users_username_index = indexes.get(u'ix_core__users_username')
+
+    if not users_uploader_index or users_username_index:
         # We don't need to do anything.
         # The database isn't in a state where it needs fixing
         #
@@ -864,12 +869,10 @@ def revert_username_index(db):
         # table copying.
 
         # Remove whichever of the not-used indexes are in place
-        if u'ix_core__users_uploader' in indexes:
-            index = indexes[u'ix_core__users_uploader']
-            index.drop()
-        if u'ix_core__users_username' in indexes:
-            index = indexes[u'ix_core__users_username']
-            index.drop()
+        if users_uploader_index:
+            users_uploader_index.drop()
+        if users_username_index:
+            users_username_index.drop()
 
         # Given we're removing indexes then adding a unique constraint
         # which *we know might fail*, thus probably rolling back the