Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
5 changes: 5 additions & 0 deletions homeassistant/components/recorder/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
LAST_REPORTED_SCHEMA_VERSION = 43

LEGACY_STATES_EVENT_ID_INDEX_SCHEMA_VERSION = 28
LEGACY_STATES_EVENT_FOREIGN_KEYS_FIXED_SCHEMA_VERSION = 43
# https://github.com/home-assistant/core/pull/120779
# fixed the foreign keys in the states table but it did
# not bump the schema version which means only databases
# created with schema 44 and later do not need the rebuild.

INTEGRATION_PLATFORM_COMPILE_STATISTICS = "compile_statistics"
INTEGRATION_PLATFORM_LIST_STATISTIC_IDS = "list_statistic_ids"
Expand Down
13 changes: 11 additions & 2 deletions homeassistant/components/recorder/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from .const import (
CONTEXT_ID_AS_BINARY_SCHEMA_VERSION,
EVENT_TYPE_IDS_SCHEMA_VERSION,
LEGACY_STATES_EVENT_FOREIGN_KEYS_FIXED_SCHEMA_VERSION,
LEGACY_STATES_EVENT_ID_INDEX_SCHEMA_VERSION,
STATES_META_SCHEMA_VERSION,
SupportedDialect,
Expand Down Expand Up @@ -2490,9 +2491,10 @@ def needs_migrate(self, instance: Recorder, session: Session) -> bool:
if self.initial_schema_version > self.max_initial_schema_version:
_LOGGER.debug(
"Data migration '%s' not needed, database created with version %s "
"after migrator was added",
"after migrator was added in version %s",
self.migration_id,
self.initial_schema_version,
self.max_initial_schema_version,
)
return False
if self.start_schema_version < self.required_schema_version:
Expand Down Expand Up @@ -2868,7 +2870,14 @@ class EventIDPostMigration(BaseRunTimeMigration):
"""Migration to remove old event_id index from states."""

migration_id = "event_id_post_migration"
max_initial_schema_version = LEGACY_STATES_EVENT_ID_INDEX_SCHEMA_VERSION - 1
# Note we don't subtract 1 from the max_initial_schema_version
# in this case because we need to run this migration on databases
# version 43 because the schema was not bumped when the table
# rebuild was added in
# https://github.com/home-assistant/core/pull/120779
# which means its only safe to assume version 44 and later
# do not need the table rebuild
max_initial_schema_version = LEGACY_STATES_EVENT_FOREIGN_KEYS_FIXED_SCHEMA_VERSION
task = MigrationTask
migration_version = 2

Expand Down
Loading