diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 0fac32bdec7..043887b7cab 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -64,6 +64,8 @@ def _apply_update(engine, new_version): # Create indexes for states _create_index(engine, "states", "ix_states_last_updated") _create_index(engine, "states", "ix_states_entity_id_created") + elif new_version == 3: + _create_index(engine, "states", "ix_states_created_domain") else: raise ValueError("No schema migration defined for version {}" .format(new_version)) diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 6dcb5dbd051..65c7dc6abb6 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -16,7 +16,7 @@ from homeassistant.remote import JSONEncoder # pylint: disable=invalid-name Base = declarative_base() -SCHEMA_VERSION = 2 +SCHEMA_VERSION = 3 _LOGGER = logging.getLogger(__name__) @@ -75,7 +75,9 @@ class States(Base): # type: ignore Index('states__significant_changes', 'domain', 'last_updated', 'entity_id'), Index('ix_states_entity_id_created', - 'entity_id', 'created'),) + 'entity_id', 'created'), + Index('ix_states_created_domain', + 'created', 'domain'),) @staticmethod def from_event(event):