Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2976558b
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,发现更多精彩内容 >>
提交
2976558b
编写于
2月 25, 2013
作者:
B
bondarev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support transactions in Migrator.run
上级
130d3a06
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
5 deletion
+42
-5
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+12
-5
activerecord/test/cases/migration_test.rb
activerecord/test/cases/migration_test.rb
+26
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
2976558b
## Rails 4.0.0 (unreleased) ##
*
Run migrate:down & migrate:up in transaction if database supports
*Alexander Bondarev*
*
Added Statement Cache to allow the caching of a single statement. The cache works by
duping the relation returned from yielding a statement, which allows skipping the AST
building phase for following executes. The cache returns results in array format.
...
...
activerecord/lib/active_record/migration.rb
浏览文件 @
2976558b
...
...
@@ -867,11 +867,18 @@ def current_migration
alias
:current
:current_migration
def
run
target
=
migrations
.
detect
{
|
m
|
m
.
version
==
@target_version
}
raise
UnknownMigrationVersionError
.
new
(
@target_version
)
if
target
.
nil?
unless
(
up?
&&
migrated
.
include?
(
target
.
version
.
to_i
))
||
(
down?
&&
!
migrated
.
include?
(
target
.
version
.
to_i
))
target
.
migrate
(
@direction
)
record_version_state_after_migrating
(
target
.
version
)
migration
=
migrations
.
detect
{
|
m
|
m
.
version
==
@target_version
}
raise
UnknownMigrationVersionError
.
new
(
@target_version
)
if
migration
.
nil?
unless
(
up?
&&
migrated
.
include?
(
migration
.
version
.
to_i
))
||
(
down?
&&
!
migrated
.
include?
(
migration
.
version
.
to_i
))
begin
ddl_transaction
(
migration
)
do
migration
.
migrate
(
@direction
)
record_version_state_after_migrating
(
migration
.
version
)
end
rescue
=>
e
canceled_msg
=
use_transaction?
(
migration
)
?
", the migration canceled"
:
""
raise
StandardError
,
"An error has occurred
#{
canceled_msg
}
:
\n\n
#{
e
}
"
,
e
.
backtrace
end
end
end
...
...
activerecord/test/cases/migration_test.rb
浏览文件 @
2976558b
...
...
@@ -258,6 +258,32 @@ def migrate(x)
"On error, the Migrator should revert schema changes but it did not."
end
def
test_migrator_one_up_with_exception_and_rollback_using_run
unless
ActiveRecord
::
Base
.
connection
.
supports_ddl_transactions?
skip
"not supported on
#{
ActiveRecord
::
Base
.
connection
.
class
}
"
end
assert_not
Person
.
column_methods_hash
.
include?
(
:last_name
)
migration
=
Class
.
new
(
ActiveRecord
::
Migration
)
{
def
version
;
100
end
def
migrate
(
x
)
add_column
"people"
,
"last_name"
,
:string
raise
'Something broke'
end
}.
new
migrator
=
ActiveRecord
::
Migrator
.
new
(
:up
,
[
migration
],
100
)
e
=
assert_raise
(
StandardError
)
{
migrator
.
run
}
assert_equal
"An error has occurred, the migration canceled:
\n\n
Something broke"
,
e
.
message
Person
.
reset_column_information
assert_not
Person
.
column_methods_hash
.
include?
(
:last_name
),
"On error, the Migrator should revert schema changes but it did not."
end
def
test_migration_without_transaction
unless
ActiveRecord
::
Base
.
connection
.
supports_ddl_transactions?
skip
"not supported on
#{
ActiveRecord
::
Base
.
connection
.
class
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录