From fe66d6295c1ca9593edad2a5e64dacbce475454e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 27 Sep 2021 19:31:40 +0200 Subject: [PATCH] Improve migration to recorder schema version 21 (#56204) --- homeassistant/components/recorder/migration.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 1a1f978be59..0e66585d86e 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -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(