提交 3aadda90 编写于 作者: R Rafael Mendonça França

Merge pull request #10025 from masarakki/fix_detect_enum_column_on_mysql

fix detect column type of enum
......@@ -82,6 +82,8 @@ def simplified_type(field_type)
def extract_limit(sql_type)
case sql_type
when /^enum\((.+)\)/i
$1.split(',').map{|enum| enum.strip.length - 2}.max
when /blob|text/i
case sql_type
when /tiny/i
......@@ -98,8 +100,6 @@ def extract_limit(sql_type)
when /^mediumint/i; 3
when /^smallint/i; 2
when /^tinyint/i; 1
when /^enum\((.+)\)/i
$1.split(',').map{|enum| enum.strip.length - 2}.max
else
super
end
......
......@@ -5,6 +5,6 @@ class EnumTest < ActiveRecord::Base
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
assert_equal 6, EnumTest.columns.first.limit
end
end
......@@ -5,6 +5,6 @@ class EnumTest < ActiveRecord::Base
end
def test_enum_limit
assert_equal 5, EnumTest.columns.first.limit
assert_equal 6, EnumTest.columns.first.limit
end
end
......@@ -52,7 +52,7 @@
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
enum_column ENUM('true','false')
enum_column ENUM('text','blob','tiny','medium','long')
)
SQL
end
......@@ -63,7 +63,7 @@
ActiveRecord::Base.connection.execute <<-SQL
CREATE TABLE enum_tests (
enum_column ENUM('true','false')
enum_column ENUM('text','blob','tiny','medium','long')
)
SQL
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册