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: