Open pushups opened 5 years ago
It's a MySQL jdbc configuration thing. I tried your example and I can't even create/migrate the database because MySQL is complaining about timezone issues. I get
Java::JavaSql::SQLException: The server time zone value 'CEST' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
So I added this to the datatabase.yml:
diff --git a/config/database.yml b/config/database.yml
index 5ae466a..dd6d54c 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -7,6 +7,8 @@
default: &default
adapter: mysql2
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+ properties:
+ serverTimezone: <%= java.util.TimeZone.getDefault.getID %>
development:
<<: *default
DB is created, migrated...and the test is passing. If I change serverTimezone
to UTC, it fails. For me:
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+
So I don't know the right value for you, but probably UTC. Also I don't really know much about MySQL these days, haven't used it in many years. The only reason I have it around is to test activerecord-jdbc-adapter ;)
Thank you @dr-itz we could not get our application to connect at all to local MySQL servers when running JRuby. After adding the serverTimezone
option you supplied above it suddenly started connecting to MySQL. Looks like if we have other properties
in the configuration that instead of the exception you saw above it just fails to connect.
This is now in the README as well: https://github.com/jruby/activerecord-jdbc-adapter#mysql-specific-notes
So... How does one go about passing config[:properties]
via DATABASE_URL
?
I have tried ?serverTimezone=
, ?properties.serverTimezone=
, ?properties[serverTimezone]=
and nothing seems to work.
It appears that activerecord-jdbcmysql-adapter is reading timestamps incorrectly. It is converting them to the local timezone and then interpreting them as a UTC time instead of keeping them in a UTC timezone.
activerecord-jdbcmysql-adapter version: 52.2
Rails version: 5.2.3
Jruby version:
Reproduction Steps:
Result: The created_at and updated_at timestamps after reading are the local time interpreted as a UTC time.
Expected result: Reading from the database doesn't change a timestamp.
I've also made an example repo where you can see this bug with a failing test: https://github.com/pushups/ar_jdbc_mysql
Some other things to note: The object is stored in the database correctly with UTC time:
Timezones are set explicitly in the database: