aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/migrations.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2014-08-08 11:39:44 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2014-08-08 11:39:44 -0500
commitf2a6db9088ae267950ec9f4e8ea3e39ec5ef89a2 (patch)
treef72dd960567ccb219a4ab44f1f662f96660deb10 /mediagoblin/db/migrations.py
parented0b981edc868046575d9e451077e79c7b0e4016 (diff)
downloadmediagoblin-f2a6db9088ae267950ec9f4e8ea3e39ec5ef89a2.tar.lz
mediagoblin-f2a6db9088ae267950ec9f4e8ea3e39ec5ef89a2.tar.xz
mediagoblin-f2a6db9088ae267950ec9f4e8ea3e39ec5ef89a2.zip
Pull the indexes out of the dictionary directly
Instead of checking for their keys and pulling them out later, that is.
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r--mediagoblin/db/migrations.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index fca7819b..faf84c15 100644
--- a/mediagoblin/db/migrations.py
+++ b/mediagoblin/db/migrations.py
@@ -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