Home Assistant Unofficial Reference 2024.12.1
schema.py
Go to the documentation of this file.
1 """Events schema repairs."""
2 
3 from __future__ import annotations
4 
5 from typing import TYPE_CHECKING
6 
7 from ...db_schema import EventData, Events
8 from ..schema import (
9  correct_db_schema_precision,
10  correct_db_schema_utf8,
11  validate_db_schema_precision,
12  validate_table_schema_has_correct_collation,
13  validate_table_schema_supports_utf8,
14 )
15 
16 if TYPE_CHECKING:
17  from ... import Recorder
18 
19 
20 def validate_db_schema(instance: Recorder) -> set[str]:
21  """Do some basic checks for common schema errors caused by manual migration."""
23  instance, EventData, (EventData.shared_data,)
24  ) | validate_db_schema_precision(instance, Events)
25  for table in (Events, EventData):
26  schema_errors |= validate_table_schema_has_correct_collation(instance, table)
27  return schema_errors
28 
29 
31  instance: Recorder,
32  schema_errors: set[str],
33 ) -> None:
34  """Correct issues detected by validate_db_schema."""
35  for table in (Events, EventData):
36  correct_db_schema_utf8(instance, table, schema_errors)
37  correct_db_schema_precision(instance, Events, schema_errors)
None correct_db_schema(Recorder instance, set[str] schema_errors)
Definition: schema.py:33
None correct_db_schema_precision(Recorder instance, type[DeclarativeBase] table_object, set[str] schema_errors)
Definition: schema.py:256
set[str] validate_table_schema_has_correct_collation(Recorder instance, type[DeclarativeBase] table_object)
Definition: schema.py:68
None correct_db_schema_utf8(Recorder instance, type[DeclarativeBase] table_object, set[str] schema_errors)
Definition: schema.py:238
set[str] validate_db_schema_precision(Recorder instance, type[DeclarativeBase] table_object)
Definition: schema.py:150
set[str] validate_table_schema_supports_utf8(Recorder instance, type[DeclarativeBase] table_object, tuple[InstrumentedAttribute,...] columns)
Definition: schema.py:47