fix detect column type of enum
enum includes text or blob or ... hooked by wrong regex
This commit is contained in:
parent
0a16cf19c2
commit
eab657b267
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user