Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
949fd758
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
949fd758
编写于
7月 07, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36604 from kamipo/fix_schema_dumping_enum
MySQL: Fix schema dumping `enum` and `set` columns correctly
上级
ef4379b2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
55 addition
and
7 deletion
+55
-7
activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
.../active_record/connection_adapters/mysql/schema_dumper.rb
+3
-1
activerecord/lib/active_record/schema_dumper.rb
activerecord/lib/active_record/schema_dumper.rb
+5
-1
activerecord/test/cases/adapters/mysql2/enum_test.rb
activerecord/test/cases/adapters/mysql2/enum_test.rb
+14
-0
activerecord/test/cases/adapters/mysql2/set_test.rb
activerecord/test/cases/adapters/mysql2/set_test.rb
+32
-0
activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb
.../test/cases/connection_adapters/mysql_type_lookup_test.rb
+1
-1
activerecord/test/schema/mysql2_specific_schema.rb
activerecord/test/schema/mysql2_specific_schema.rb
+0
-4
未找到文件。
activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
浏览文件 @
949fd758
...
...
@@ -41,13 +41,15 @@ def schema_type(column)
case
column
.
sql_type
when
/\Atimestamp\b/
:timestamp
when
/\A(?:enum|set)\b/
column
.
sql_type
else
super
end
end
def
schema_limit
(
column
)
super
unless
/\A(?:
tiny|medium|long)?(?:text|blob)
/
.
match?
(
column
.
sql_type
)
super
unless
/\A(?:
enum|set|(?:tiny|medium|long)?(?:text|blob))\b
/
.
match?
(
column
.
sql_type
)
end
def
schema_precision
(
column
)
...
...
activerecord/lib/active_record/schema_dumper.rb
浏览文件 @
949fd758
...
...
@@ -146,7 +146,11 @@ def table(table, stream)
raise
StandardError
,
"Unknown type '
#{
column
.
sql_type
}
' for column '
#{
column
.
name
}
'"
unless
@connection
.
valid_type?
(
column
.
type
)
next
if
column
.
name
==
pk
type
,
colspec
=
column_spec
(
column
)
tbl
.
print
" t.
#{
type
}
#{
column
.
name
.
inspect
}
"
if
type
.
is_a?
(
Symbol
)
tbl
.
print
" t.
#{
type
}
#{
column
.
name
.
inspect
}
"
else
tbl
.
print
" t.column
#{
column
.
name
.
inspect
}
,
#{
type
.
inspect
}
"
end
tbl
.
print
",
#{
format_colspec
(
colspec
)
}
"
if
colspec
.
present?
tbl
.
puts
end
...
...
activerecord/test/cases/adapters/mysql2/enum_test.rb
浏览文件 @
949fd758
# frozen_string_literal: true
require
"cases/helper"
require
"support/schema_dumping_helper"
class
Mysql2EnumTest
<
ActiveRecord
::
Mysql2TestCase
include
SchemaDumpingHelper
class
EnumTest
<
ActiveRecord
::
Base
end
def
setup
EnumTest
.
connection
.
create_table
:enum_tests
,
id:
false
,
force:
true
do
|
t
|
t
.
column
:enum_column
,
"enum('text','blob','tiny','medium','long','unsigned','bigint')"
end
end
def
test_enum_limit
column
=
EnumTest
.
columns_hash
[
"enum_column"
]
assert_equal
8
,
column
.
limit
...
...
@@ -20,4 +29,9 @@ def test_should_not_be_bigint
column
=
EnumTest
.
columns_hash
[
"enum_column"
]
assert_not_predicate
column
,
:bigint?
end
def
test_schema_dumping
schema
=
dump_table_schema
"enum_tests"
assert_match
%r{t
\.
column "enum_column", "enum
\(
'text','blob','tiny','medium','long','unsigned','bigint'
\)
"$}
,
schema
end
end
activerecord/test/cases/adapters/mysql2/set_test.rb
0 → 100644
浏览文件 @
949fd758
# frozen_string_literal: true
require
"cases/helper"
require
"support/schema_dumping_helper"
class
Mysql2SetTest
<
ActiveRecord
::
Mysql2TestCase
include
SchemaDumpingHelper
class
SetTest
<
ActiveRecord
::
Base
end
def
setup
SetTest
.
connection
.
create_table
:set_tests
,
id:
false
,
force:
true
do
|
t
|
t
.
column
:set_column
,
"set('text','blob','tiny','medium','long','unsigned','bigint')"
end
end
def
test_should_not_be_unsigned
column
=
SetTest
.
columns_hash
[
"set_column"
]
assert_not_predicate
column
,
:unsigned?
end
def
test_should_not_be_bigint
column
=
SetTest
.
columns_hash
[
"set_column"
]
assert_not_predicate
column
,
:bigint?
end
def
test_schema_dumping
schema
=
dump_table_schema
"set_tests"
assert_match
%r{t
\.
column "set_column", "set
\(
'text','blob','tiny','medium','long','unsigned','bigint'
\)
"$}
,
schema
end
end
activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb
浏览文件 @
949fd758
...
...
@@ -40,7 +40,7 @@ def test_set_type_with_value_matching_other_type
end
def
test_enum_type_with_value_matching_other_type
assert_lookup_type
:string
,
"ENUM('unicode', '8bit', 'none')"
assert_lookup_type
:string
,
"ENUM('unicode', '8bit', 'none'
, 'time'
)"
end
def
test_binary_types
...
...
activerecord/test/schema/mysql2_specific_schema.rb
浏览文件 @
949fd758
...
...
@@ -62,10 +62,6 @@
t
.
binary
:binary_column
,
limit:
1
end
create_table
:enum_tests
,
id:
false
,
force:
true
do
|
t
|
t
.
column
:enum_column
,
"ENUM('text','blob','tiny','medium','long','unsigned','bigint')"
end
execute
"DROP PROCEDURE IF EXISTS ten"
execute
<<~
SQL
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录