Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
910c59ff
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,发现更多精彩内容 >>
提交
910c59ff
编写于
2月 17, 2012
作者:
P
Peter Mitchell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correctly print names of non-timestamped migrations with db:migrate:status
上级
b9ad0975
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
3 deletion
+52
-3
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+3
-2
railties/test/application/rake/migrations_test.rb
railties/test/application/rake/migrations_test.rb
+49
-1
未找到文件。
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
910c59ff
...
...
@@ -207,11 +207,12 @@ db_namespace = namespace :db do
next
# means "return" for rake task
end
db_list
=
ActiveRecord
::
Base
.
connection
.
select_values
(
"SELECT version FROM
#{
ActiveRecord
::
Migrator
.
schema_migrations_table_name
}
"
)
db_list
.
map!
{
|
version
|
"%.3d"
%
version
}
file_list
=
[]
ActiveRecord
::
Migrator
.
migrations_paths
.
each
do
|
path
|
Dir
.
foreach
(
path
)
do
|
file
|
#
only files matching "20091231235959
_some_name.rb" pattern
if
match_data
=
/^(\d{
14
})_(.+)\.rb$/
.
match
(
file
)
#
match "20091231235959_some_name.rb" and "001
_some_name.rb" pattern
if
match_data
=
/^(\d{
3,
})_(.+)\.rb$/
.
match
(
file
)
status
=
db_list
.
delete
(
match_data
[
1
])
?
'up'
:
'down'
file_list
<<
[
status
,
match_data
[
1
],
match_data
[
2
].
humanize
]
end
...
...
railties/test/application/rake/migrations_test.rb
浏览文件 @
910c59ff
...
...
@@ -67,7 +67,7 @@ class AMigration < ActiveRecord::Migration
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
...
...
@@ -80,6 +80,27 @@ class AMigration < ActiveRecord::Migration
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
end
test
'migration status without timestamps'
do
add_to_config
(
'config.active_record.timestamped_migrations = false'
)
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=1`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
end
test
'test migration status after rollback and redo'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
...
...
@@ -104,6 +125,33 @@ class AMigration < ActiveRecord::Migration
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
test
'migration status after rollback and redo without timestamps'
do
add_to_config
(
'config.active_record.timestamped_migrations = false'
)
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
end
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=2`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/down\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:redo`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录