Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c5f11438
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,发现更多精彩内容 >>
提交
c5f11438
编写于
6月 03, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36384 from guigs/fix-invalid-schema-when-pk-column-has-comment
Fix invalid schema dump when primary key column has a comment
上级
0a88d991
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
28 addition
and
2 deletion
+28
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+6
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
...tive_record/connection_adapters/abstract/schema_dumper.rb
+1
-1
activerecord/test/cases/comment_test.rb
activerecord/test/cases/comment_test.rb
+21
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
c5f11438
*
Fix invalid schema when primary key column has a comment.
Fixes #29966.
*Guilherme Goettems Schneider*
*
Fix table comment also being applied to the primary key column.
*Guilherme Goettems Schneider*
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
浏览文件 @
c5f11438
...
...
@@ -15,7 +15,7 @@ def column_spec(column)
def
column_spec_for_primary_key
(
column
)
return
{}
if
default_primary_key?
(
column
)
spec
=
{
id:
schema_type
(
column
).
inspect
}
spec
.
merge!
(
prepare_column_options
(
column
).
except!
(
:null
))
spec
.
merge!
(
prepare_column_options
(
column
).
except!
(
:null
,
:comment
))
spec
[
:default
]
||=
"nil"
if
explicit_primary_key_default?
(
column
)
spec
end
...
...
activerecord/test/cases/comment_test.rb
浏览文件 @
c5f11438
...
...
@@ -14,6 +14,9 @@ class Commented < ActiveRecord::Base
class
BlankComment
<
ActiveRecord
::
Base
end
class
PkCommented
<
ActiveRecord
::
Base
end
setup
do
@connection
=
ActiveRecord
::
Base
.
connection
...
...
@@ -35,8 +38,13 @@ class BlankComment < ActiveRecord::Base
t
.
index
:absent_comment
end
@connection
.
create_table
(
"pk_commenteds"
,
comment:
"Table comment"
,
id:
false
,
force:
true
)
do
|
t
|
t
.
integer
:id
,
comment:
"Primary key comment"
,
primary_key:
true
end
Commented
.
reset_column_information
BlankComment
.
reset_column_information
PkCommented
.
reset_column_information
end
teardown
do
...
...
@@ -44,7 +52,7 @@ class BlankComment < ActiveRecord::Base
@connection
.
drop_table
"blank_comments"
,
if_exists:
true
end
def
test_primary_key_comment
def
test_
default_
primary_key_comment
column
=
Commented
.
columns_hash
[
"id"
]
assert_nil
column
.
comment
end
...
...
@@ -169,5 +177,17 @@ def test_change_column_comment_to_nil
column
=
Commented
.
columns_hash
[
"name"
]
assert_nil
column
.
comment
end
def
test_comment_on_primary_key
column
=
PkCommented
.
columns_hash
[
"id"
]
assert_equal
"Primary key comment"
,
column
.
comment
assert_equal
"Table comment"
,
@connection
.
table_comment
(
"pk_commenteds"
)
end
def
test_schema_dump_with_primary_key_comment
output
=
dump_table_schema
"pk_commenteds"
assert_match
%r[create_table "pk_commenteds",.*
\s
+comment: "Table comment"]
,
output
assert_no_match
%r[create_table "pk_commenteds",.*
\s
+comment: "Primary key comment"]
,
output
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录