mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge PR #43141
This commit is contained in:
commit
75fea0bd95
4 changed files with 50 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
* Add a deprecation warning when `prepared_statements` configuration is not
|
||||
set for the mysql2 adapter.
|
||||
|
||||
*Thiago Araujo and Stefanni Brasil*
|
||||
|
||||
* Fix `QueryMethods#in_order_of` to handle empty order list.
|
||||
|
||||
```ruby
|
||||
|
|
|
@ -56,6 +56,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def initialize(connection, logger, connection_options, config)
|
||||
check_prepared_statements_deprecation(config)
|
||||
superclass_config = config.reverse_merge(prepared_statements: false)
|
||||
super(connection, logger, connection_options, superclass_config)
|
||||
configure_connection
|
||||
|
@ -140,6 +141,14 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
private
|
||||
def check_prepared_statements_deprecation(config)
|
||||
if !config.key?(:prepared_statements)
|
||||
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||
The default value of `prepared_statements` for the mysql2 adapter will be changed from +false+ to +true+ in Rails 7.2.
|
||||
MSG
|
||||
end
|
||||
end
|
||||
|
||||
def connect
|
||||
@connection = self.class.new_client(@config)
|
||||
configure_connection
|
||||
|
|
|
@ -40,6 +40,38 @@ class Mysql2AdapterTest < ActiveRecord::Mysql2TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_mysql2_prepared_statements_default_deprecation_warning
|
||||
fake_connection = Class.new do
|
||||
def query_options
|
||||
{}
|
||||
end
|
||||
|
||||
def query(*)
|
||||
end
|
||||
|
||||
def close
|
||||
end
|
||||
end.new
|
||||
|
||||
assert_deprecated do
|
||||
ActiveRecord::ConnectionAdapters::Mysql2Adapter.new(
|
||||
fake_connection,
|
||||
ActiveRecord::Base.logger,
|
||||
nil,
|
||||
{ socket: File::NULL }
|
||||
)
|
||||
end
|
||||
|
||||
assert_not_deprecated do
|
||||
ActiveRecord::ConnectionAdapters::Mysql2Adapter.new(
|
||||
fake_connection,
|
||||
ActiveRecord::Base.logger,
|
||||
nil,
|
||||
{ socket: File::NULL, prepared_statements: false }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def test_exec_query_nothing_raises_with_no_result_queries
|
||||
assert_nothing_raised do
|
||||
with_example_table do
|
||||
|
|
|
@ -42,6 +42,8 @@ connections:
|
|||
collation: utf8mb4_unicode_ci
|
||||
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
|
||||
prepared_statements: true
|
||||
<% else %>
|
||||
prepared_statements: false
|
||||
<% end %>
|
||||
<% if ENV['MYSQL_HOST'] %>
|
||||
host: <%= ENV['MYSQL_HOST'] %>
|
||||
|
@ -55,6 +57,8 @@ connections:
|
|||
collation: utf8mb4_general_ci
|
||||
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
|
||||
prepared_statements: true
|
||||
<% else %>
|
||||
prepared_statements: false
|
||||
<% end %>
|
||||
<% if ENV['MYSQL_HOST'] %>
|
||||
host: <%= ENV['MYSQL_HOST'] %>
|
||||
|
|
Loading…
Reference in a new issue