diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index b715ef9bc58..a310161457b 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -68,7 +68,7 @@ class Base(DeclarativeBase): """Base class for tables.""" -SCHEMA_VERSION = 40 +SCHEMA_VERSION = 41 _LOGGER = logging.getLogger(__name__) @@ -348,7 +348,9 @@ class EventTypes(Base): __table_args__ = (_DEFAULT_TABLE_ARGS,) __tablename__ = TABLE_EVENT_TYPES event_type_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True) - event_type: Mapped[str | None] = mapped_column(String(MAX_LENGTH_EVENT_EVENT_TYPE)) + event_type: Mapped[str | None] = mapped_column( + String(MAX_LENGTH_EVENT_EVENT_TYPE), index=True + ) def __repr__(self) -> str: """Return string representation of instance for debugging.""" @@ -597,7 +599,9 @@ class StatesMeta(Base): __table_args__ = (_DEFAULT_TABLE_ARGS,) __tablename__ = TABLE_STATES_META metadata_id: Mapped[int] = mapped_column(Integer, Identity(), primary_key=True) - entity_id: Mapped[str | None] = mapped_column(String(MAX_LENGTH_STATE_ENTITY_ID)) + entity_id: Mapped[str | None] = mapped_column( + String(MAX_LENGTH_STATE_ENTITY_ID), index=True + ) def __repr__(self) -> str: """Return string representation of instance for debugging.""" diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 5b2180773a3..74fbcf307fb 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -1054,6 +1054,9 @@ def _apply_update( # noqa: C901 "statistics_short_term", "ix_statistics_short_term_metadata_id", ) + elif new_version == 41: + _create_index(session_maker, "event_types", "ix_event_types_event_type") + _create_index(session_maker, "states_meta", "ix_states_meta_entity_id") else: raise ValueError(f"No schema migration defined for version {new_version}")