Pull the indexes out of the dictionary directly
Instead of checking for their keys and pulling them out later, that is.
This commit is contained in:
parent
ed0b981edc
commit
f2a6db9088
@ -839,8 +839,13 @@ def revert_username_index(db):
|
|||||||
user_table = inspect_table(metadata, "core__users")
|
user_table = inspect_table(metadata, "core__users")
|
||||||
indexes = {index.name: index for index in user_table.indexes}
|
indexes = {index.name: index for index in user_table.indexes}
|
||||||
|
|
||||||
if not (u'ix_core__users_uploader' in indexes or
|
# index from unnecessary migration
|
||||||
u'ix_core__users_username' in indexes):
|
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.
|
# We don't need to do anything.
|
||||||
# The database isn't in a state where it needs fixing
|
# The database isn't in a state where it needs fixing
|
||||||
#
|
#
|
||||||
@ -864,12 +869,10 @@ def revert_username_index(db):
|
|||||||
# table copying.
|
# table copying.
|
||||||
|
|
||||||
# Remove whichever of the not-used indexes are in place
|
# Remove whichever of the not-used indexes are in place
|
||||||
if u'ix_core__users_uploader' in indexes:
|
if users_uploader_index:
|
||||||
index = indexes[u'ix_core__users_uploader']
|
users_uploader_index.drop()
|
||||||
index.drop()
|
if users_username_index:
|
||||||
if u'ix_core__users_username' in indexes:
|
users_username_index.drop()
|
||||||
index = indexes[u'ix_core__users_username']
|
|
||||||
index.drop()
|
|
||||||
|
|
||||||
# Given we're removing indexes then adding a unique constraint
|
# Given we're removing indexes then adding a unique constraint
|
||||||
# which *we know might fail*, thus probably rolling back the
|
# which *we know might fail*, thus probably rolling back the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user