Merge pull request #39408 from kamipo/remove_limit_on_enum

Remove unused `limit` on `enum` and `set` columns in MySQL
This commit is contained in:
Ryuta Kamizono 2020-05-25 19:08:47 +09:00 committed by GitHub
commit 8e7080e4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 17 deletions

@ -565,17 +565,8 @@ def initialize_type_map(m = type_map)
m.alias_type %r(year)i, "integer"
m.alias_type %r(bit)i, "binary"
m.register_type(%r(enum)i) do |sql_type|
limit = sql_type[/^enum\s*\((.+)\)/i, 1]
.split(",").map { |enum| enum.strip.length - 2 }.max
MysqlString.new(limit: limit)
end
m.register_type(%r(^set)i) do |sql_type|
limit = sql_type[/^set\s*\((.+)\)/i, 1]
.split(",").map { |set| set.strip.length - 1 }.sum - 1
MysqlString.new(limit: limit)
end
m.register_type %r(^enum)i, MysqlString.new
m.register_type %r(^set)i, MysqlString.new
end
def register_integer_type(mapping, key, **options)

@ -49,7 +49,7 @@ def schema_type(column)
end
def schema_limit(column)
super unless /\A(?:enum|set|(?:tiny|medium|long)?(?:text|blob))\b/.match?(column.sql_type)
super unless /\A(?:tiny|medium|long)?(?:text|blob)\b/.match?(column.sql_type)
end
def schema_precision(column)

@ -15,11 +15,6 @@ def setup
end
end
def test_enum_limit
column = EnumTest.columns_hash["enum_column"]
assert_equal 8, column.limit
end
def test_should_not_be_unsigned
column = EnumTest.columns_hash["enum_column"]
assert_not_predicate column, :unsigned?