aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrooke Kuhlmann <brooke@alchemists.io>2018-10-15 16:58:22 -0600
committerBrooke Kuhlmann <brooke@alchemists.io>2018-10-16 10:09:06 -0600
commite1f6821105a23fe4dc6e37903fb642a253e89e81 (patch)
treebbc1c2f77f117dcc4b3db93e02c145af95905e53
parent134dab46e4e94d7e6e37cec43dca8183fe72aea6 (diff)
downloadrails-e1f6821105a23fe4dc6e37903fb642a253e89e81.tar.gz
rails-e1f6821105a23fe4dc6e37903fb642a253e89e81.tar.bz2
rails-e1f6821105a23fe4dc6e37903fb642a253e89e81.zip
Refactored abstract MySQL adapter to support lazy version check.
Will allow sub classes to override the protected `#check_version` method hook if desired. For example, this will be most helpful in sub classes that wish to support lazy initialization because the version check can be postponed until the connection is ready to be initialized.
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index d40f38fb77..5ad3fdbb88 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -26,6 +26,7 @@ module ActiveRecord
# ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans = false
class_attribute :emulate_booleans, default: true
+ SUPPORTED_VERSION = "5.5.8"
NATIVE_DATABASE_TYPES = {
primary_key: "bigint auto_increment PRIMARY KEY",
string: { name: "varchar", limit: 255 },
@@ -54,10 +55,7 @@ module ActiveRecord
super(connection, logger, config)
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
-
- if version < "5.5.8"
- raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.5.8."
- end
+ check_version
end
def version #:nodoc:
@@ -534,6 +532,15 @@ module ActiveRecord
end
end
+ protected
+
+ def check_version
+ if version < SUPPORTED_VERSION
+ raise "Your version of MySQL (#{version_string}) is too old. Active Record supports " \
+ "MySQL >= #{SUPPORTED_VERSION}."
+ end
+ end
+
private
def combine_multi_statements(total_sql)
total_sql.each_with_object([]) do |sql, total_sql_chunks|