Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/recorder/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def _migrate_columns_to_timestamp(
text(
"UPDATE events set time_fired_ts="
"IF(time_fired is NULL,0,"
"UNIX_TIMESTAMP(CONVERT_TZ(time_fired,'+00:00',@@global.time_zone))"
"UNIX_TIMESTAMP(time_fired)"
") "
"where time_fired_ts is NULL "
"LIMIT 250000;"
Expand All @@ -1009,10 +1009,10 @@ def _migrate_columns_to_timestamp(
text(
"UPDATE states set last_updated_ts="
"IF(last_updated is NULL,0,"
"UNIX_TIMESTAMP(CONVERT_TZ(last_updated,'+00:00',@@global.time_zone)) "
"UNIX_TIMESTAMP(last_updated) "
"), "
"last_changed_ts="
"UNIX_TIMESTAMP(CONVERT_TZ(last_changed,'+00:00',@@global.time_zone)) "
"UNIX_TIMESTAMP(last_changed) "
"where last_updated_ts is NULL "
"LIMIT 250000;"
)
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/recorder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ def setup_connection_for_dialect(
or MARIA_DB_107 <= version < MARIADB_WITH_FIXED_IN_QUERIES_107
or MARIA_DB_108 <= version < MARIADB_WITH_FIXED_IN_QUERIES_108
)

# Ensure all times are using UTC to avoid issues with daylight savings
execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'")
elif dialect_name == SupportedDialect.POSTGRESQL:
# Historically we have marked PostgreSQL as having slow range in select
# but this may not be true for all versions. We should investigate
Expand Down
3 changes: 2 additions & 1 deletion tests/components/recorder/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ def _make_cursor_mock(*_):

util.setup_connection_for_dialect(instance_mock, "mysql", dbapi_connection, True)

assert len(execute_args) == 2
assert len(execute_args) == 3
assert execute_args[0] == "SET session wait_timeout=28800"
assert execute_args[1] == "SELECT VERSION()"
assert execute_args[2] == "SET time_zone = '+00:00'"


@pytest.mark.parametrize(
Expand Down