Skip to content

Commit 6369b0f

Browse files
committed
case for postgres and sqlite in test
1 parent 31e2887 commit 6369b0f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/dfe/analytics/services/entity_table_checks.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,25 @@ def supported_adapter_and_environment?
4545
end
4646

4747
def fetch_current_timestamp_in_time_zone
48-
Time.use_zone(TIME_ZONE) { Time.zone.now.iso8601(6) }
48+
utc_timestamp = case connection.adapter_name.downcase
49+
when 'postgresql', 'postgis'
50+
connection.select_value("SELECT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')::text AS current_timestamp_utc")
51+
when 'sqlite3', 'sqlite'
52+
connection.select_value("SELECT CURRENT_TIMESTAMP AS current_timestamp_utc")
53+
else
54+
nil
55+
end
56+
57+
if utc_timestamp.present?
58+
Time.use_zone(TIME_ZONE) do
59+
utc_time = Time.find_zone('UTC').parse(utc_timestamp)
60+
utc_time.in_time_zone(Time.zone).iso8601(6)
61+
end
62+
else
63+
# Fallback: use application clock but make the choice explicit
64+
Rails.logger.warn("fetch_current_timestamp_in_time_zone: unknown DB adapter '#{connection.adapter_name}', falling back to app clock")
65+
Time.use_zone(TIME_ZONE) { Time.zone.now.iso8601(6) }
66+
end
4967
end
5068

5169
def id_column_exists_for_entity?(entity_name)

0 commit comments

Comments
 (0)