Remove unused columns from states/events tables (#68078)

pull/68054/head
J. Nick Koston 2022-03-13 20:44:55 -10:00 committed by GitHub
parent a6c189b450
commit b18096fc54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 23 deletions

View File

@ -907,9 +907,9 @@ class Recorder(threading.Thread):
try:
if event.event_type == EVENT_STATE_CHANGED:
dbevent = Events.from_event(event, event_data="{}")
dbevent.event_data = None
else:
dbevent = Events.from_event(event)
dbevent.created = event.time_fired
self.event_session.add(dbevent)
except (TypeError, ValueError):
_LOGGER.warning("Event is not JSON serializable: %s", event)
@ -928,7 +928,6 @@ class Recorder(threading.Thread):
if not has_new_state:
dbstate.state = None
dbstate.event = dbevent
dbstate.created = event.time_fired
self.event_session.add(dbstate)
if has_new_state:
self._old_states[dbstate.entity_id] = dbstate

View File

@ -92,7 +92,6 @@ class Events(Base): # type: ignore[misc,valid-type]
event_data = Column(Text().with_variant(mysql.LONGTEXT, "mysql"))
origin = Column(String(MAX_LENGTH_EVENT_ORIGIN))
time_fired = Column(DATETIME_TYPE, index=True)
created = Column(DATETIME_TYPE, default=dt_util.utcnow)
context_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
context_user_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
context_parent_id = Column(String(MAX_LENGTH_EVENT_CONTEXT_ID), index=True)
@ -161,7 +160,6 @@ class States(Base): # type: ignore[misc,valid-type]
)
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"), index=True)
event = relationship("Events", uselist=False)
old_state = relationship("States", remote_side=[state_id])

View File

@ -356,7 +356,6 @@ async def test_purge_edge_case(
event_type="EVENT_TEST_PURGE",
event_data="{}",
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)
@ -368,7 +367,6 @@ async def test_purge_edge_case(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
event_id=1001,
)
)
@ -416,7 +414,6 @@ async def test_purge_cutoff_date(
event_type="KEEP",
event_data="{}",
origin="LOCAL",
created=timestamp_keep,
time_fired=timestamp_keep,
)
)
@ -428,7 +425,6 @@ async def test_purge_cutoff_date(
attributes="{}",
last_changed=timestamp_keep,
last_updated=timestamp_keep,
created=timestamp_keep,
event_id=1000,
)
)
@ -439,7 +435,6 @@ async def test_purge_cutoff_date(
event_type="PURGE",
event_data="{}",
origin="LOCAL",
created=timestamp_purge,
time_fired=timestamp_purge,
)
)
@ -451,7 +446,6 @@ async def test_purge_cutoff_date(
attributes="{}",
last_changed=timestamp_purge,
last_updated=timestamp_purge,
created=timestamp_purge,
event_id=1000 + row,
)
)
@ -519,7 +513,6 @@ async def test_purge_filtered_states(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
)
)
# Add states and state_changed events that should be keeped
@ -541,7 +534,6 @@ async def test_purge_filtered_states(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=1,
)
timestamp = dt_util.utcnow() - timedelta(days=4)
@ -552,7 +544,6 @@ async def test_purge_filtered_states(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=2,
)
state_3 = States(
@ -562,7 +553,6 @@ async def test_purge_filtered_states(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=62, # keep
)
session.add_all((state_1, state_2, state_3))
@ -573,7 +563,6 @@ async def test_purge_filtered_states(
event_type="EVENT_KEEP",
event_data="{}",
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)
@ -652,7 +641,6 @@ async def test_purge_filtered_events(
event_type="EVENT_PURGE",
event_data="{}",
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)
@ -745,7 +733,6 @@ async def test_purge_filtered_events_state_changed(
event_type="EVENT_KEEP",
event_data="{}",
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)
@ -758,7 +745,6 @@ async def test_purge_filtered_events_state_changed(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=1,
)
timestamp = dt_util.utcnow() - timedelta(days=4)
@ -769,7 +755,6 @@ async def test_purge_filtered_events_state_changed(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=2,
)
state_3 = States(
@ -779,7 +764,6 @@ async def test_purge_filtered_events_state_changed(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
old_state_id=62, # keep
)
session.add_all((state_1, state_2, state_3))
@ -991,7 +975,6 @@ async def _add_test_events(hass: HomeAssistant, instance: recorder.Recorder):
event_type=event_type,
event_data=json.dumps(event_data),
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)
@ -1094,7 +1077,6 @@ def _add_state_and_state_changed_event(
attributes="{}",
last_changed=timestamp,
last_updated=timestamp,
created=timestamp,
event_id=event_id,
)
)
@ -1104,7 +1086,6 @@ def _add_state_and_state_changed_event(
event_type=EVENT_STATE_CHANGED,
event_data="{}",
origin="LOCAL",
created=timestamp,
time_fired=timestamp,
)
)