diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-21 18:32:29 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-21 18:32:29 +0900 |
commit | 1b21d951a9efda8bc8f99cdf6328afb45335cabb (patch) | |
tree | e2e5eececd2b39a8ce051305f996ab9821037ea9 /activerecord/lib/active_record/connection_adapters | |
parent | 97d3f5472ee2bbef630eaff4e20f9dcc7839d34f (diff) | |
download | rails-1b21d951a9efda8bc8f99cdf6328afb45335cabb.tar.gz rails-1b21d951a9efda8bc8f99cdf6328afb45335cabb.tar.bz2 rails-1b21d951a9efda8bc8f99cdf6328afb45335cabb.zip |
Prevent extra `SET time zone` in `configure_connection` (#28413)
`SET time zone 'value'` is an alias for `SET timezone TO 'value'`.
https://www.postgresql.org/docs/current/static/sql-set.html
So if `variables["timezone"]` is specified, it is enough to
`SET timezone` once.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a2a9017bd9..878c9c8ccd 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -688,18 +688,20 @@ module ActiveRecord # Use standard-conforming strings so we don't have to do the E'...' dance. set_standard_conforming_strings + variables = @config.fetch(:variables, {}).stringify_keys + # If using Active Record's time zone support configure the connection to return # TIMESTAMP WITH ZONE types in UTC. - # (SET TIME ZONE does not use an equals sign like other SET variables) - if ActiveRecord::Base.default_timezone == :utc - execute("SET time zone 'UTC'", "SCHEMA") - elsif @local_tz - execute("SET time zone '#{@local_tz}'", "SCHEMA") + unless variables["timezone"] + if ActiveRecord::Base.default_timezone == :utc + variables["timezone"] = "UTC" + elsif @local_tz + variables["timezone"] = @local_tz + end end # SET statements from :variables config hash # https://www.postgresql.org/docs/current/static/sql-set.html - variables = @config[:variables] || {} variables.map do |k, v| if v == ":default" || v == :default # Sets the value to the global or compile default |