mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add index to event_type and entity_id (#89676)
This commit is contained in:
parent
b620e5d8a6
commit
dbc0890ce8
@ -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."""
|
||||
|
@ -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}")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user