I came across a use case where I needed provide session variables for
a connection.
For example some of these [1]. I see it was reported here [2] 5 years ago.
Would something like passing:
session_variables: time_zone=UTC,someVar=someValue
in the database.yml config be acceptable as a solution?
Thanks,
[1] MySQL :: MySQL 8.0 Reference Manual :: 5.1.8 Server System Variables
[2] #3579 ActiveRecord not setting/checking MySQL session variable time_zone - Ruby on Rails - rails
Vipul A.M.
It seems to already be implemented. Matthew pointed there is
variables = @config.fetch(:variables, {}).stringify_keys
# Increase timeout so the server doesn't disconnect us.
wait_timeout = self.class.type_cast_config_to_integer(@config[:wait_timeout])
wait_timeout = 2147483 unless wait_timeout.is_a?(Integer)
variables["wait_timeout"] = wait_timeout
defaults = [":default", :default].to_set
# Make MySQL reject illegal values rather than truncating or blanking them, see
# https://dev.mysql.com/doc/refman/en/sql-mode.html#sqlmode_strict_all_tables
# If the user has provided another value for sql_mode, don't replace it.
and
I see Session variables for mysql, mysql2, and postgresql adapters can be set · rails/rails@97d06e8 · GitHub
was implemented 2 years ago.
Although its not documented.
Sorry for the noise and thanks Matthew!
Vipul A.M.
+91-8149-204995