Recover from previously failed statistics migrations (#101781)

* Handle statistics columns being unmigrated from previous downgrades

If the user downgraded HA from 2023.3.x to an older version without
restoring the database and they upgrade again with the same database
they will have unmigrated statistics columns since we only migrate them
once.

As its expensive to check, we do not want to check every time
at startup, so we will only do this one more time since the
risk that someone will downgrade to an older version is very
low at this point.

* add guard to sqlite to prevent re-migrate

* test

* move test to insert with old schema

* use helper

* normalize timestamps

* remove

* add check

* add fallback migration

* add fallback migration

* commit

* remove useless logging

* remove useless logging

* do the other columns at the same time

* coverage

* dry

* comment

* Update tests/components/recorder/test_migration_from_schema_32.py
This commit is contained in:
J. Nick Koston 2023-10-22 17:34:43 -10:00 committed by GitHub
parent 4ee9a6f130
commit 268425b5e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 819 additions and 53 deletions

View file

@ -68,7 +68,7 @@ class Base(DeclarativeBase):
"""Base class for tables."""
SCHEMA_VERSION = 41
SCHEMA_VERSION = 42
_LOGGER = logging.getLogger(__name__)