diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index f77305277c8..50a49f1d4ce 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -743,7 +743,7 @@ class Recorder(threading.Thread): return self.schema_version = schema_status.current_version - if schema_status.valid: + if not schema_status.migration_needed and not schema_status.schema_errors: self._setup_run() else: self.migration_in_progress = True @@ -752,7 +752,7 @@ class Recorder(threading.Thread): self.hass.add_job(self.async_connection_success) # First do non-live migration steps, if needed - if not schema_status.valid: + if schema_status.migration_needed: result, schema_status = self._migrate_schema_offline(schema_status) if not result: self._notify_migration_failed() @@ -774,8 +774,8 @@ class Recorder(threading.Thread): # we restart before startup finishes return - # Do live migration steps, if needed - if not schema_status.valid: + # Do live migration steps and repairs, if needed + if schema_status.migration_needed or schema_status.schema_errors: result, schema_status = self._migrate_schema_live_and_setup_run( schema_status ) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 0af0788a42a..a5bb61e1fc5 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -193,9 +193,9 @@ class SchemaValidationStatus: """Store schema validation status.""" current_version: int + migration_needed: bool schema_errors: set[str] start_version: int - valid: bool def _schema_is_current(current_version: int) -> bool: @@ -223,10 +223,8 @@ def validate_db_schema( # columns may otherwise not exist etc. schema_errors = _find_schema_errors(hass, instance, session_maker) - valid = is_current and not schema_errors - return SchemaValidationStatus( - current_version, schema_errors, current_version, valid + current_version, not is_current, schema_errors, current_version )