Improve migration to recorder schema version 21 (#56204)
This commit is contained in:
parent
e5642a8648
commit
fe66d6295c
1 changed files with 11 additions and 1 deletions
|
@ -502,14 +502,24 @@ def _apply_update(instance, session, new_version, old_version): # noqa: C901
|
|||
],
|
||||
)
|
||||
elif new_version == 21:
|
||||
if engine.dialect.name in ["mysql", "oracle", "postgresql"]:
|
||||
data_type = "DOUBLE PRECISION"
|
||||
else:
|
||||
data_type = "FLOAT"
|
||||
_add_columns(
|
||||
connection,
|
||||
"statistics",
|
||||
["sum_increase DOUBLE PRECISION"],
|
||||
[f"sum_increase {data_type}"],
|
||||
)
|
||||
# Try to change the character set of the statistic_meta table
|
||||
if engine.dialect.name == "mysql":
|
||||
for table in ("events", "states", "statistics_meta"):
|
||||
_LOGGER.warning(
|
||||
"Updating character set and collation of table %s to utf8mb4. "
|
||||
"Note: this can take several minutes on large databases and slow "
|
||||
"computers. Please be patient!",
|
||||
table,
|
||||
)
|
||||
with contextlib.suppress(SQLAlchemyError):
|
||||
connection.execute(
|
||||
text(
|
||||
|
|
Loading…
Add table
Reference in a new issue