mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix data migration never finishing when database has invalid datetimes (#89474)
* Fix data migration never finishing when database has invalid datetimes If there were impossible datetime values in the database (likely from a manual sqlite to MySQL conversion) the conversion would never complete * Update homeassistant/components/recorder/migration.py
This commit is contained in:
parent
d828263ee3
commit
9e1ba8534a
@ -1106,7 +1106,7 @@ def _migrate_columns_to_timestamp(
|
|||||||
result = session.connection().execute(
|
result = session.connection().execute(
|
||||||
text(
|
text(
|
||||||
"UPDATE events set time_fired_ts="
|
"UPDATE events set time_fired_ts="
|
||||||
"IF(time_fired is NULL,0,"
|
"IF(time_fired is NULL or UNIX_TIMESTAMP(time_fired) is NULL,0,"
|
||||||
"UNIX_TIMESTAMP(time_fired)"
|
"UNIX_TIMESTAMP(time_fired)"
|
||||||
") "
|
") "
|
||||||
"where time_fired_ts is NULL "
|
"where time_fired_ts is NULL "
|
||||||
@ -1119,7 +1119,7 @@ def _migrate_columns_to_timestamp(
|
|||||||
result = session.connection().execute(
|
result = session.connection().execute(
|
||||||
text(
|
text(
|
||||||
"UPDATE states set last_updated_ts="
|
"UPDATE states set last_updated_ts="
|
||||||
"IF(last_updated is NULL,0,"
|
"IF(last_updated is NULL or UNIX_TIMESTAMP(last_updated) is NULL,0,"
|
||||||
"UNIX_TIMESTAMP(last_updated) "
|
"UNIX_TIMESTAMP(last_updated) "
|
||||||
"), "
|
"), "
|
||||||
"last_changed_ts="
|
"last_changed_ts="
|
||||||
@ -1195,7 +1195,7 @@ def _migrate_statistics_columns_to_timestamp(
|
|||||||
result = session.connection().execute(
|
result = session.connection().execute(
|
||||||
text(
|
text(
|
||||||
f"UPDATE {table} set start_ts="
|
f"UPDATE {table} set start_ts="
|
||||||
"IF(start is NULL,0,"
|
"IF(start is NULL or UNIX_TIMESTAMP(start) is NULL,0,"
|
||||||
"UNIX_TIMESTAMP(start) "
|
"UNIX_TIMESTAMP(start) "
|
||||||
"), "
|
"), "
|
||||||
"created_ts="
|
"created_ts="
|
||||||
|
Loading…
x
Reference in New Issue
Block a user