未验证 提交 bb0c02e9 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #34232 from kamipo/check_version

Consistently extract checking version for all adapters
......@@ -125,6 +125,8 @@ def initialize(connection, logger = nil, config = {}) # :nodoc:
@advisory_locks_enabled = self.class.type_cast_config_to_boolean(
config.fetch(:advisory_locks, true)
)
check_version
end
def replica?
......@@ -502,6 +504,9 @@ def default_index_type?(index) # :nodoc:
end
private
def check_version
end
def type_map
@type_map ||= Type::TypeMap.new.tap do |mapping|
initialize_type_map(mapping)
......
......@@ -26,7 +26,6 @@ class AbstractMysqlAdapter < AbstractAdapter
# 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 },
......@@ -55,7 +54,6 @@ def initialize(connection, logger, connection_options, config)
super(connection, logger, config)
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
check_version
end
def version #:nodoc:
......@@ -532,16 +530,13 @@ def insert_fixtures_set(fixture_set, tables_to_delete = [])
end
end
protected
private
def check_version
if version < SUPPORTED_VERSION
raise "Your version of MySQL (#{version_string}) is too old. Active Record supports " \
"MySQL >= #{SUPPORTED_VERSION}."
if version < "5.5.8"
raise "Your version of MySQL (#{version_string}) is too old. Active Record supports MySQL >= 5.5.8."
end
end
private
def combine_multi_statements(total_sql)
total_sql.each_with_object([]) do |sql, total_sql_chunks|
previous_packet = total_sql_chunks.last
......
......@@ -43,9 +43,14 @@ def postgresql_connection(config)
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
conn_params.slice!(*valid_conn_param_keys)
# The postgres drivers don't allow the creation of an unconnected PG::Connection object,
# so just pass a nil connection object for the time being.
ConnectionAdapters::PostgreSQLAdapter.new(nil, logger, conn_params, config)
conn = PG.connect(conn_params)
ConnectionAdapters::PostgreSQLAdapter.new(conn, logger, conn_params, config)
rescue ::PG::Error => error
if error.message.include?("does not exist")
raise ActiveRecord::NoDatabaseError
else
raise
end
end
end
......@@ -220,15 +225,11 @@ def initialize(connection, logger, connection_parameters, config)
@local_tz = nil
@max_identifier_length = nil
connect
configure_connection
add_pg_encoders
@statements = StatementPool.new @connection,
self.class.type_cast_config_to_integer(config[:statement_limit])
if postgresql_version < 90100
raise "Your version of PostgreSQL (#{postgresql_version}) is too old. Active Record supports PostgreSQL >= 9.1."
end
add_pg_decoders
@type_map = Type::HashLookupTypeMap.new
......@@ -410,6 +411,12 @@ def default_index_type?(index) # :nodoc:
end
private
def check_version
if postgresql_version < 90100
raise "Your version of PostgreSQL (#{postgresql_version}) is too old. Active Record supports PostgreSQL >= 9.1."
end
end
# See https://www.postgresql.org/docs/current/static/errcodes-appendix.html
VALUE_LIMIT_VIOLATION = "22001"
NUMERIC_VALUE_OUT_OF_RANGE = "22003"
......@@ -699,12 +706,6 @@ def prepare_statement(sql)
def connect
@connection = PG.connect(@connection_parameters)
configure_connection
rescue ::PG::Error => error
if error.message.include?("does not exist")
raise ActiveRecord::NoDatabaseError
else
raise
end
end
# Configures the encoding, verbosity, schema search path, and time zone of the connection.
......
......@@ -105,11 +105,6 @@ def initialize(connection, logger, connection_options, config)
@active = true
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
if sqlite_version < "3.8.0"
raise "Your version of SQLite (#{sqlite_version}) is too old. Active Record supports SQLite >= 3.8."
end
configure_connection
end
......@@ -401,6 +396,12 @@ def insert_fixtures_set(fixture_set, tables_to_delete = [])
end
private
def check_version
if sqlite_version < "3.8.0"
raise "Your version of SQLite (#{sqlite_version}) is too old. Active Record supports SQLite >= 3.8."
end
end
def initialize_type_map(m = type_map)
super
register_class_with_limit m, %r(int)i, SQLite3Integer
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册