Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
aedcd683
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,体验更适合开发者的 AI 搜索 >>
提交
aedcd683
编写于
12月 18, 2012
作者:
M
Marc-Andre Lafortune
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migration generators use `change` even for destructive methods [#8267]
上级
7204d3c6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
47 deletion
+16
-47
activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
...generators/active_record/migration/templates/migration.rb
+4
-16
railties/test/generators/migration_generator_test.rb
railties/test/generators/migration_generator_test.rb
+12
-31
未找到文件。
activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
浏览文件 @
aedcd683
...
...
@@ -21,28 +21,16 @@ def change
end
end
<%- else -%>
def
up
def
change
<
% attributes.each
do
|
attribute
|
-
%>
<%- if migration_action -%>
<
%- if attribute.reference? -%>
remove_reference :<%= table_name %>
,
:<
%=
attribute
.
name
%><%=
', polymorphic: true' if attribute.polymorphic?
%>
remove_reference :<%= table_name %>
,
:<
%=
attribute
.
name
%><%=
attribute.inject_options
%>
<
%- else -%>
remove_column :<%= table_name %>
,
:<
%=
attribute
.
name
%>
<%- end -%>
<
%- end -%>
<%- end -%>
end
def
down
<
% attributes.reverse.each
do
|
attribute
|
-
%>
<%- if migration_action -%>
<
%- if attribute.reference? -%>
add_reference :<%= table_name %>
,
:<
%=
attribute
.
name
%><%= attribute.inject_options %>
<
%- else -%>
add_column :<%= table_name %>
,
:<
%=
attribute
.
name
%>, :<%= attribute.type %>
<
%= attribute.inject_options %>
<%- if attribute.has_index? -%>
add
_index :<%=
table_name
%>, :<%= attribute.index_name %>
<
%= attribute.inject_index_options %>
remove
_index
:<
%=
table_name
%>, :<%= attribute.index_name %>
<
%= attribute.inject_index_options %>
<%- end -%>
remove_column :<%=
table_name
%>, :<%= attribute.name %>
,
:<
%=
attribute
.
type
%><%= attribute.inject_options %>
<
%- end -%>
<%- end -%>
<
%- end -%>
...
...
railties/test/generators/migration_generator_test.rb
浏览文件 @
aedcd683
...
...
@@ -53,15 +53,10 @@ def test_remove_migration_with_indexed_attribute
run_generator
[
migration
,
"title:string:index"
,
"body:text"
]
assert_migration
"db/migrate/
#{
migration
}
.rb"
do
|
content
|
assert_method
:up
,
content
do
|
up
|
assert_match
(
/remove_column :posts, :title/
,
up
)
assert_match
(
/remove_column :posts, :body/
,
up
)
end
assert_method
:down
,
content
do
|
down
|
assert_match
(
/add_column :posts, :title, :string/
,
down
)
assert_match
(
/add_column :posts, :body, :text/
,
down
)
assert_match
(
/add_index :posts, :title/
,
down
)
assert_method
:change
,
content
do
|
change
|
assert_match
(
/remove_column :posts, :title, :string/
,
change
)
assert_match
(
/remove_column :posts, :body, :text/
,
change
)
assert_match
(
/remove_index :posts, :title/
,
change
)
end
end
end
...
...
@@ -71,14 +66,9 @@ def test_remove_migration_with_attributes
run_generator
[
migration
,
"title:string"
,
"body:text"
]
assert_migration
"db/migrate/
#{
migration
}
.rb"
do
|
content
|
assert_method
:up
,
content
do
|
up
|
assert_match
(
/remove_column :posts, :title/
,
up
)
assert_match
(
/remove_column :posts, :body/
,
up
)
end
assert_method
:down
,
content
do
|
down
|
assert_match
(
/add_column :posts, :title, :string/
,
down
)
assert_match
(
/add_column :posts, :body, :text/
,
down
)
assert_method
:change
,
content
do
|
change
|
assert_match
(
/remove_column :posts, :title, :string/
,
change
)
assert_match
(
/remove_column :posts, :body, :text/
,
change
)
end
end
end
...
...
@@ -88,14 +78,9 @@ def test_remove_migration_with_references_options
run_generator
[
migration
,
"author:belongs_to"
,
"distributor:references{polymorphic}"
]
assert_migration
"db/migrate/
#{
migration
}
.rb"
do
|
content
|
assert_method
:up
,
content
do
|
up
|
assert_match
(
/remove_reference :books, :author/
,
up
)
assert_match
(
/remove_reference :books, :distributor, polymorphic: true/
,
up
)
end
assert_method
:down
,
content
do
|
down
|
assert_match
(
/add_reference :books, :author, index: true/
,
down
)
assert_match
(
/add_reference :books, :distributor, polymorphic: true, index: true/
,
down
)
assert_method
:change
,
content
do
|
change
|
assert_match
(
/remove_reference :books, :author, index: true/
,
change
)
assert_match
(
/remove_reference :books, :distributor, polymorphic: true, index: true/
,
change
)
end
end
end
...
...
@@ -192,12 +177,8 @@ def test_should_create_empty_migrations_if_name_not_start_with_add_or_remove
run_generator
[
migration
,
"title:string"
,
"content:text"
]
assert_migration
"db/migrate/
#{
migration
}
.rb"
do
|
content
|
assert_method
:up
,
content
do
|
up
|
assert_match
(
/^\s*$/
,
up
)
end
assert_method
:down
,
content
do
|
down
|
assert_match
(
/^\s*$/
,
down
)
assert_method
:change
,
content
do
|
change
|
assert_match
(
/^\s*$/
,
change
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录