Change character set of statistics_meta table to utf8 (#56011)

This commit is contained in:
Erik Montnemery 2021-09-09 17:24:20 +02:00 committed by GitHub
parent dd9bfe7aa0
commit a47532c69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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}")

View File

@ -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)