From 52e9f76f94e4e04b149bd9ac67ec58347b53dc2b Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 29 Sep 2021 11:25:50 +0200 Subject: [PATCH] Tweak DB migration to schema version 21 (#56767) --- homeassistant/components/recorder/migration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 0e66585d86e..8eef957bc88 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -522,9 +522,11 @@ def _apply_update(instance, session, new_version, old_version): # noqa: C901 ) with contextlib.suppress(SQLAlchemyError): connection.execute( + # Using LOCK=EXCLUSIVE to prevent the database from corrupting + # https://github.com/home-assistant/core/issues/56104 text( f"ALTER TABLE {table} CONVERT TO " - "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" + "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci LOCK=EXCLUSIVE" ) ) elif new_version == 22: