mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 12:45:28 +02:00
Change character set of statistics_meta table to utf8 (#56011)
This commit is contained in:
@@ -507,6 +507,17 @@ def _apply_update(engine, session, new_version, old_version): # noqa: C901
|
||||
"statistics",
|
||||
["sum_increase DOUBLE PRECISION"],
|
||||
)
|
||||
# Try to change the character set of the statistic_meta table
|
||||
if engine.dialect.name == "mysql":
|
||||
try:
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE statistics_meta CONVERT TO "
|
||||
"CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
|
||||
)
|
||||
)
|
||||
except SQLAlchemyError:
|
||||
pass
|
||||
else:
|
||||
raise ValueError(f"No schema migration defined for version {new_version}")
|
||||
|
||||
|
@@ -238,6 +238,7 @@ class Statistics(Base): # type: ignore
|
||||
__table_args__ = (
|
||||
# Used for fetching statistics for a certain entity at a specific time
|
||||
Index("ix_statistics_statistic_id_start", "metadata_id", "start"),
|
||||
{"mysql_default_charset": "utf8mb4", "mysql_collate": "utf8mb4_unicode_ci"},
|
||||
)
|
||||
__tablename__ = TABLE_STATISTICS
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
Reference in New Issue
Block a user