1 """Statistics schema repairs."""
3 from __future__
import annotations
6 from typing
import TYPE_CHECKING
8 from ...db_schema
import Statistics, StatisticsMeta, StatisticsShortTerm
10 correct_db_schema_precision,
11 correct_db_schema_utf8,
12 validate_db_schema_precision,
13 validate_table_schema_has_correct_collation,
14 validate_table_schema_supports_utf8,
18 from ...
import Recorder
20 _LOGGER = logging.getLogger(__name__)
24 """Do some basic checks for common schema errors caused by manual migration."""
25 schema_errors: set[str] = set()
27 instance, StatisticsMeta, (StatisticsMeta.statistic_id,)
29 for table
in (Statistics, StatisticsShortTerm):
34 "Detected statistics schema errors: %s",
", ".join(sorted(schema_errors))
41 schema_errors: set[str],
43 """Correct issues detected by validate_db_schema."""
45 for table
in (Statistics, StatisticsShortTerm):
None correct_db_schema_precision(Recorder instance, type[DeclarativeBase] table_object, set[str] schema_errors)
set[str] validate_table_schema_has_correct_collation(Recorder instance, type[DeclarativeBase] table_object)
None correct_db_schema_utf8(Recorder instance, type[DeclarativeBase] table_object, set[str] schema_errors)
set[str] validate_db_schema_precision(Recorder instance, type[DeclarativeBase] table_object)
set[str] validate_table_schema_supports_utf8(Recorder instance, type[DeclarativeBase] table_object, tuple[InstrumentedAttribute,...] columns)
set[str] validate_db_schema(Recorder instance)
None correct_db_schema(Recorder instance, set[str] schema_errors)