Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/recorder/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ def _apply_update(engine, new_version, old_version):
if engine.dialect.name == "mysql":
_modify_columns(engine, "events", ["event_data LONGTEXT"])
_modify_columns(engine, "states", ["attributes LONGTEXT"])
elif new_version == 13:
if engine.dialect.name == "mysql":
_modify_columns(engine, "events", ["time_fired DATETIME(6)"])
_modify_columns(engine, "events", ["created DATETIME(6)"])
_modify_columns(engine, "states", ["last_changed DATETIME(6)"])
_modify_columns(engine, "states", ["last_updated DATETIME(6)"])
_modify_columns(engine, "states", ["created DATETIME(6)"])
Comment thread
agners marked this conversation as resolved.
Outdated
else:
raise ValueError(f"No schema migration defined for version {new_version}")

Expand Down
16 changes: 10 additions & 6 deletions homeassistant/components/recorder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# pylint: disable=invalid-name
Base = declarative_base()

SCHEMA_VERSION = 12
SCHEMA_VERSION = 13

_LOGGER = logging.getLogger(__name__)

Expand All @@ -39,6 +39,10 @@

ALL_TABLES = [TABLE_STATES, TABLE_EVENTS, TABLE_RECORDER_RUNS, TABLE_SCHEMA_CHANGES]

DATETIME_TYPE = DateTime(timezone=True).with_variant(
mysql.DATETIME(timezone=True, fsp=6), "mysql"
)


class Events(Base): # type: ignore
"""Event history data."""
Expand All @@ -52,8 +56,8 @@ class Events(Base): # type: ignore
event_type = Column(String(32))
event_data = Column(Text().with_variant(mysql.LONGTEXT, "mysql"))
origin = Column(String(32))
time_fired = Column(DateTime(timezone=True), index=True)
created = Column(DateTime(timezone=True), default=dt_util.utcnow)
time_fired = Column(DATETIME_TYPE, index=True)
created = Column(DATETIME_TYPE, default=dt_util.utcnow)
context_id = Column(String(36), index=True)
context_user_id = Column(String(36), index=True)
context_parent_id = Column(String(36), index=True)
Expand Down Expand Up @@ -123,9 +127,9 @@ class States(Base): # type: ignore
event_id = Column(
Integer, ForeignKey("events.event_id", ondelete="CASCADE"), index=True
)
last_changed = Column(DateTime(timezone=True), default=dt_util.utcnow)
last_updated = Column(DateTime(timezone=True), default=dt_util.utcnow, index=True)
created = Column(DateTime(timezone=True), default=dt_util.utcnow)
last_changed = Column(DATETIME_TYPE, default=dt_util.utcnow)
last_updated = Column(DATETIME_TYPE, default=dt_util.utcnow, index=True)
created = Column(DATETIME_TYPE, default=dt_util.utcnow)
old_state_id = Column(
Integer, ForeignKey("states.state_id", ondelete="NO ACTION"), index=True
)
Expand Down