mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Make sure character set of events, states tables is utf8 (#56012)
* Make sure character set of events, states tables is utf8 * Pylint * Apply suggestions from code review
This commit is contained in:
parent
1b0e014783
commit
88dbc6373f
@ -1,4 +1,5 @@
|
|||||||
"""Schema migration helpers."""
|
"""Schema migration helpers."""
|
||||||
|
import contextlib
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -509,15 +510,14 @@ def _apply_update(engine, session, new_version, old_version): # noqa: C901
|
|||||||
)
|
)
|
||||||
# Try to change the character set of the statistic_meta table
|
# Try to change the character set of the statistic_meta table
|
||||||
if engine.dialect.name == "mysql":
|
if engine.dialect.name == "mysql":
|
||||||
try:
|
for table in ("events", "states", "statistics_meta"):
|
||||||
connection.execute(
|
with contextlib.suppress(SQLAlchemyError):
|
||||||
text(
|
connection.execute(
|
||||||
"ALTER TABLE statistics_meta CONVERT TO "
|
text(
|
||||||
"CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
|
f"ALTER TABLE {table} CONVERT TO "
|
||||||
|
"CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
except SQLAlchemyError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"No schema migration defined for version {new_version}")
|
raise ValueError(f"No schema migration defined for version {new_version}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user