diff --git a/lib/active_record/connection_adapters/cockroachdb_adapter.rb b/lib/active_record/connection_adapters/cockroachdb_adapter.rb index e0e478df..422b5056 100644 --- a/lib/active_record/connection_adapters/cockroachdb_adapter.rb +++ b/lib/active_record/connection_adapters/cockroachdb_adapter.rb @@ -206,6 +206,10 @@ def supports_string_to_array_coercion? @crdb_version >= 2020 end + def needs_numeric_override? + @crdb_version < 2210 + end + def supports_partitioned_indexes? false end @@ -232,7 +236,7 @@ def initialize(connection, logger, conn_params, config) if crdb_version_string.include? "v1." version_num = 1 elsif crdb_version_string.include? "v2." - version_num 2 + version_num = 2 elsif crdb_version_string.include? "v19.1." version_num = 1910 elsif crdb_version_string.include? "v19.2." @@ -245,8 +249,10 @@ def initialize(connection, logger, conn_params, config) version_num = 2110 elsif crdb_version_string.include? "v21.2.0" version_num = 2120 - else + elsif crdb_version_string.include? "v21.2." version_num = 2121 + else + version_num = 2210 end @crdb_version = version_num @@ -291,21 +297,23 @@ def initialize_type_map(m = type_map) # Once that PR is merged, we can call super at the top. super(m) - # Override numeric type. This is almost identical to the default, + # Override numeric type pre-22.1. This is almost identical to the default, # except that the conditional based on the fmod is changed. - m.register_type "numeric" do |_, fmod, sql_type| - precision = extract_precision(sql_type) - scale = extract_scale(sql_type) - - # If fmod is -1, that means that precision is defined but not - # scale, or neither is defined. - if fmod && fmod == -1 && !precision.nil? - # Below comment is from ActiveRecord - # FIXME: Remove this class, and the second argument to - # lookups on PG - Type::DecimalWithoutScale.new(precision: precision) - else - OID::Decimal.new(precision: precision, scale: scale) + if needs_numeric_override? + m.register_type "numeric" do |_, fmod, sql_type| + precision = extract_precision(sql_type) + scale = extract_scale(sql_type) + + # If fmod is -1, that means that precision is defined but not + # scale, or neither is defined. + if fmod && fmod == -1 && !precision.nil? + # Below comment is from ActiveRecord + # FIXME: Remove this class, and the second argument to + # lookups on PG + Type::DecimalWithoutScale.new(precision: precision) + else + OID::Decimal.new(precision: precision, scale: scale) + end end end end