mirror of
https://github.com/home-assistant/core.git
synced 2025-08-14 01:55:18 +02:00
fix
This commit is contained in:
@@ -1319,15 +1319,16 @@ def migrate_event_type_ids(instance: Recorder) -> bool:
|
||||
db_event_type.event_type
|
||||
] = db_event_type.event_type_id
|
||||
|
||||
for event_id, event_type in events:
|
||||
session.execute(
|
||||
update(Events),
|
||||
session.execute(
|
||||
update(Events),
|
||||
[
|
||||
{
|
||||
"event_id": event_id,
|
||||
"event_type_id": event_type_to_id[event_type],
|
||||
},
|
||||
)
|
||||
session.commit()
|
||||
}
|
||||
for event_id, event_type in events
|
||||
],
|
||||
)
|
||||
|
||||
# If there is more work to do return False
|
||||
# so that we can be called again
|
||||
|
@@ -11,6 +11,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from homeassistant.components import recorder
|
||||
from homeassistant.components.recorder import SQLITE_URL_PREFIX, core, statistics
|
||||
from homeassistant.components.recorder.queries import select_event_type_ids
|
||||
from homeassistant.components.recorder.util import session_scope
|
||||
from homeassistant.core import EVENT_STATE_CHANGED, Event, EventOrigin, State
|
||||
from homeassistant.helpers import recorder as recorder_helper
|
||||
@@ -87,7 +88,9 @@ def test_migrate_times(caplog: pytest.LogCaptureFixture, tmpdir) -> None:
|
||||
|
||||
with patch.object(recorder, "db_schema", old_db_schema), patch.object(
|
||||
recorder.migration, "SCHEMA_VERSION", old_db_schema.SCHEMA_VERSION
|
||||
), patch.object(core, "EventData", old_db_schema.EventData), patch.object(
|
||||
), patch.object(core, "EventTypes", old_db_schema.EventTypes), patch.object(
|
||||
core, "EventData", old_db_schema.EventData
|
||||
), patch.object(
|
||||
core, "States", old_db_schema.States
|
||||
), patch.object(
|
||||
core, "Events", old_db_schema.Events
|
||||
@@ -117,8 +120,10 @@ def test_migrate_times(caplog: pytest.LogCaptureFixture, tmpdir) -> None:
|
||||
wait_recording_done(hass)
|
||||
with session_scope(hass=hass) as session:
|
||||
result = list(
|
||||
session.query(recorder.db_schema.Events).where(
|
||||
recorder.db_schema.Events.event_type == "custom_event"
|
||||
session.query(recorder.db_schema.Events).filter(
|
||||
recorder.db_schema.Events.event_type_id.in_(
|
||||
select_event_type_ids(("custom_event",))
|
||||
)
|
||||
)
|
||||
)
|
||||
assert len(result) == 1
|
||||
|
Reference in New Issue
Block a user