Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7ce850cd
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,发现更多精彩内容 >>
提交
7ce850cd
编写于
4月 19, 2017
作者:
R
Rafael França
提交者:
GitHub
4月 19, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #28166 from bogdanvlviv/fix_migration_tasks
Fix migration tasks
上级
2b181538
bb9d6eb0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
6 deletion
+78
-6
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+9
-0
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+13
-5
railties/test/application/rake/migrations_test.rb
railties/test/application/rake/migrations_test.rb
+56
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
7ce850cd
*
Raise error
`UnknownMigrationVersionError`
on the movement of migrations
when the current migration does not exist.
*bogdanvlviv*
*
Fix
`bin/rails db:forward`
first migration.
*bogdanvlviv*
*
Support Descending Indexes for MySQL.
MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
...
...
activerecord/lib/active_record/migration.rb
浏览文件 @
7ce850cd
...
...
@@ -1104,13 +1104,21 @@ def migration_files(paths)
def
move
(
direction
,
migrations_paths
,
steps
)
migrator
=
new
(
direction
,
migrations
(
migrations_paths
))
start_index
=
migrator
.
migrations
.
index
(
migrator
.
current_migration
)
if
start_index
finish
=
migrator
.
migrations
[
start_index
+
steps
]
version
=
finish
?
finish
.
version
:
0
send
(
direction
,
migrations_paths
,
version
)
if
current_version
!=
0
&&
!
migrator
.
current_migration
raise
UnknownMigrationVersionError
.
new
(
current_version
)
end
start_index
=
if
current_version
==
0
0
else
migrator
.
migrations
.
index
(
migrator
.
current_migration
)
end
finish
=
migrator
.
migrations
[
start_index
+
steps
]
version
=
finish
?
finish
.
version
:
0
send
(
direction
,
migrations_paths
,
version
)
end
end
...
...
railties/test/application/rake/migrations_test.rb
浏览文件 @
7ce850cd
...
...
@@ -142,6 +142,62 @@ class AMigration < ActiveRecord::Migration::Current
end
end
test
"migration status after rollback and forward"
do
Dir
.
chdir
(
app_path
)
do
`bin/rails generate model user username:string password:string;
bin/rails generate migration add_email_to_users email:string;
bin/rails db:migrate`
output
=
`bin/rails db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
`bin/rails db:rollback STEP=2`
output
=
`bin/rails db:migrate:status`
assert_match
(
/down\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
`bin/rails db:forward STEP=2`
output
=
`bin/rails db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
end
test
"raise error on any move when current migration does not exist"
do
Dir
.
chdir
(
app_path
)
do
`bin/rails generate model user username:string password:string;
bin/rails generate migration add_email_to_users email:string;
bin/rails db:migrate
rm db/migrate/*email*.rb`
output
=
`bin/rails db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+\** NO FILE \**/
,
output
)
output
=
`bin/rails db:rollback 2>&1`
assert_match
(
/rails aborted!/
,
output
)
assert_match
(
/ActiveRecord::UnknownMigrationVersionError:/
,
output
)
assert_match
(
/No migration with version number\s\d{14}\./
,
output
)
output
=
`bin/rails db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+\** NO FILE \**/
,
output
)
output
=
`bin/rails db:forward 2>&1`
assert_match
(
/rails aborted!/
,
output
)
assert_match
(
/ActiveRecord::UnknownMigrationVersionError:/
,
output
)
assert_match
(
/No migration with version number\s\d{14}\./
,
output
)
output
=
`bin/rails db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+\** NO FILE \**/
,
output
)
end
end
test
"migration status after rollback and redo without timestamps"
do
add_to_config
(
"config.active_record.timestamped_migrations = false"
)
...
...
@@ -232,7 +288,6 @@ class TwoMigration < ActiveRecord::Migration::Current
rm db/migrate/*email*.rb`
output
=
`bin/rails db:migrate:status`
File
.
write
(
"test.txt"
,
output
)
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+\** NO FILE \**/
,
output
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录