From 255d706c24048ff62f22ba6dbe510dd58315bdd6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 24 Jun 2020 11:56:01 -0500 Subject: [PATCH] Avoid creating a column in v8 schema that is removed in v9 schema (#37062) --- homeassistant/components/recorder/migration.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index ca8f668d476..1cff6d178ad 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -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