Avoid creating a column in v8 schema that is removed in v9 schema (#37062)

This commit is contained in:
J. Nick Koston 2020-06-24 11:56:01 -05:00 committed by GitHub
parent cc8e0ef942
commit 255d706c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -155,6 +155,11 @@ def _drop_index(engine, table_name, index_name):
"Finished dropping index %s from table %s", index_name, table_name
)
else:
if index_name == "ix_states_context_parent_id":
# Was only there on nightly so we do not want
# to generate log noise or issues about it.
return
_LOGGER.warning(
"Failed to drop index %s from table %s. Schema "
"Migration will continue; this is not a "
@ -261,9 +266,7 @@ def _apply_update(engine, new_version, old_version):
_create_index(engine, "states", "ix_states_entity_id")
elif new_version == 8:
_add_columns(engine, "events", ["context_parent_id CHARACTER(36)"])
_add_columns(engine, "states", ["context_parent_id CHARACTER(36)"])
_add_columns(engine, "states", ["old_state_id INTEGER"])
_create_index(engine, "states", "ix_states_context_parent_id")
_create_index(engine, "events", "ix_events_context_parent_id")
elif new_version == 9:
# We now get the context from events with a join
@ -276,6 +279,8 @@ def _apply_update(engine, new_version, old_version):
#
_drop_index(engine, "states", "ix_states_context_id")
_drop_index(engine, "states", "ix_states_context_user_id")
# This index won't be there if they were not running
# nightly but we don't treat that as a critical issue
_drop_index(engine, "states", "ix_states_context_parent_id")
# Redundant keys on composite index:
# We already have ix_states_entity_id_last_updated