Support non-live database migration (#72433)

* Support non-live database migration

* Tweak startup order, add test

* Address review comments

* Fix typo

* Clarify comment about promoting dependencies

* Tweak

* Fix merge mistake

* Fix some tests

* Fix additional test

* Fix additional test

* Adjust tests

* Improve test coverage
This commit is contained in:
Erik Montnemery
2022-07-22 15:11:34 +02:00
committed by GitHub
parent 9d0a252ca7
commit fd6ffef52f
20 changed files with 993 additions and 61 deletions

View File

@@ -552,7 +552,7 @@ def write_lock_db_sqlite(instance: Recorder) -> Generator[None, None, None]:
def async_migration_in_progress(hass: HomeAssistant) -> bool:
"""Determine is a migration is in progress.
"""Determine if a migration is in progress.
This is a thin wrapper that allows us to change
out the implementation later.
@@ -563,6 +563,18 @@ def async_migration_in_progress(hass: HomeAssistant) -> bool:
return instance.migration_in_progress
def async_migration_is_live(hass: HomeAssistant) -> bool:
"""Determine if a migration is live.
This is a thin wrapper that allows us to change
out the implementation later.
"""
if DATA_INSTANCE not in hass.data:
return False
instance: Recorder = hass.data[DATA_INSTANCE]
return instance.migration_is_live
def second_sunday(year: int, month: int) -> date:
"""Return the datetime.date for the second sunday of a month."""
second = date(year, month, FIRST_POSSIBLE_SUNDAY)