提交 2fb2913b 编写于 作者: R Rafael Mendonça França

Merge pull request #15237 from sgrif/sg-move-extract-scale

Move extract_scale to decimal type
......@@ -22,8 +22,8 @@ module Type # :nodoc:
class << self
def extract_scale(sql_type)
case sql_type
when /^(numeric|decimal|number)\((\d+)\)/i then 0
when /^(numeric|decimal|number)\((\d+)(,(\d+))\)/i then $4.to_i
when /\((\d+)\)/ then 0
when /\((\d+)(,(\d+))\)/ then $3.to_i
end
end
end
......
......@@ -4,6 +4,8 @@ module Type
class Decimal < Value # :nodoc:
include Numeric
delegate :extract_scale, to: Type
def type
:decimal
end
......
......@@ -3,10 +3,7 @@ module ConnectionAdapters
module Type
class Value # :nodoc:
def type; end
def extract_scale(sql_type)
Type.extract_scale(sql_type)
end
def extract_scale(sql_type); end
def type_cast(value)
cast_value(value) unless value.nil?
......
......@@ -353,9 +353,9 @@ def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
output = standard_dump
# Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers
if current_adapter?(:OracleAdapter)
assert_match %r{t.integer\s+"atoms_in_universe",\s+precision: 38,\s+scale: 0}, output
assert_match %r{t.integer\s+"atoms_in_universe",\s+precision: 38}, output
else
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 55,\s+scale: 0}, output
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 55}, output
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册