diff --git a/homeassistant/components/recorder/auto_repairs/statistics/duplicates.py b/homeassistant/components/recorder/auto_repairs/statistics/duplicates.py index 06a5c5258f185aea7a09e9d0eaab967a6c351240..b73744ef0d1b450a67d2a5dee6a66341c57ff480 100644 --- a/homeassistant/components/recorder/auto_repairs/statistics/duplicates.py +++ b/homeassistant/components/recorder/auto_repairs/statistics/duplicates.py @@ -247,12 +247,11 @@ def delete_statistics_meta_duplicates(instance: Recorder, session: Session) -> N """Identify and delete duplicated statistics_meta. This is used when migrating from schema version 28 to schema version 29. + Note: If this needs to be called during live schema migration it needs to + be modified to reload the statistics_meta_manager. """ deleted_statistics_rows = _delete_statistics_meta_duplicates(session) if deleted_statistics_rows: - statistics_meta_manager = instance.statistics_meta_manager - statistics_meta_manager.reset() - statistics_meta_manager.load(session) _LOGGER.info( "Deleted %s duplicated statistics_meta rows", deleted_statistics_rows ) diff --git a/homeassistant/components/recorder/const.py b/homeassistant/components/recorder/const.py index 066ae938971a2a1a50bc42574a7b818cef78eda2..bc9094483179cfb69fee55d7f83358ffdaf946bd 100644 --- a/homeassistant/components/recorder/const.py +++ b/homeassistant/components/recorder/const.py @@ -54,7 +54,6 @@ ATTR_APPLY_FILTER = "apply_filter" KEEPALIVE_TIME = 30 -STATISTICS_ROWS_SCHEMA_VERSION = 23 CONTEXT_ID_AS_BINARY_SCHEMA_VERSION = 36 EVENT_TYPE_IDS_SCHEMA_VERSION = 37 STATES_META_SCHEMA_VERSION = 38 diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index 002d8937e3abe3f025db64d66bfa24972050c22a..0c80d9792681f9f5308000c9b6c7874e85a1b2ba 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -63,7 +63,6 @@ from .const import ( MYSQLDB_URL_PREFIX, SQLITE_MAX_BIND_VARS, SQLITE_URL_PREFIX, - STATISTICS_ROWS_SCHEMA_VERSION, SupportedDialect, ) from .db_schema import ( @@ -797,9 +796,7 @@ class Recorder(threading.Thread): # since we want the frontend queries to avoid a thundering # herd of queries to find the statistics meta data if # there are a lot of statistics graphs on the frontend. - schema_version = self.schema_version - if schema_version >= STATISTICS_ROWS_SCHEMA_VERSION: - self.statistics_meta_manager.load(session) + self.statistics_meta_manager.load(session) migration_changes: dict[str, int] = { row[0]: row[1]