Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4e4e9ad4
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,发现更多精彩内容 >>
提交
4e4e9ad4
编写于
3月 16, 2010
作者:
J
Josh Susser
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
record migration timestamp when migrations run
上级
c283cdd6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
8 deletion
+58
-8
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+10
-7
activerecord/test/cases/migration_test.rb
activerecord/test/cases/migration_test.rb
+48
-1
未找到文件。
activerecord/lib/active_record/migration.rb
浏览文件 @
4e4e9ad4
...
@@ -628,7 +628,7 @@ def run
...
@@ -628,7 +628,7 @@ def run
raise
UnknownMigrationVersionError
.
new
(
@target_version
)
if
target
.
nil?
raise
UnknownMigrationVersionError
.
new
(
@target_version
)
if
target
.
nil?
unless
(
up?
&&
migrated
.
include?
(
target
.
version
.
to_i
))
||
(
down?
&&
!
migrated
.
include?
(
target
.
version
.
to_i
))
unless
(
up?
&&
migrated
.
include?
(
target
.
version
.
to_i
))
||
(
down?
&&
!
migrated
.
include?
(
target
.
version
.
to_i
))
target
.
migrate
(
@direction
)
target
.
migrate
(
@direction
)
record_version_state_after_migrating
(
target
.
version
)
record_version_state_after_migrating
(
target
)
end
end
end
end
...
@@ -664,7 +664,7 @@ def migrate
...
@@ -664,7 +664,7 @@ def migrate
begin
begin
ddl_transaction
do
ddl_transaction
do
migration
.
migrate
(
@direction
)
migration
.
migrate
(
@direction
)
record_version_state_after_migrating
(
migration
.
version
)
record_version_state_after_migrating
(
migration
)
end
end
rescue
=>
e
rescue
=>
e
canceled_msg
=
Base
.
connection
.
supports_ddl_transactions?
?
"this and "
:
""
canceled_msg
=
Base
.
connection
.
supports_ddl_transactions?
?
"this and "
:
""
...
@@ -690,16 +690,19 @@ def migrated
...
@@ -690,16 +690,19 @@ def migrated
end
end
private
private
def
record_version_state_after_migrating
(
version
)
def
record_version_state_after_migrating
(
target
)
table
=
Arel
::
Table
.
new
(
self
.
class
.
schema_migrations_table_name
)
table
=
Arel
::
Table
.
new
(
self
.
class
.
schema_migrations_table_name
)
@migrated_versions
||=
[]
@migrated_versions
||=
[]
if
down?
if
down?
@migrated_versions
.
delete
(
version
)
@migrated_versions
.
delete
(
target
.
version
)
table
.
where
(
table
[
"version"
].
eq
(
version
.
to_s
)).
delete
table
.
where
(
table
[
"version"
].
eq
(
target
.
version
.
to_s
)).
delete
else
else
@migrated_versions
.
push
(
version
).
sort!
@migrated_versions
.
push
(
target
.
version
).
sort!
table
.
insert
table
[
"version"
]
=>
version
.
to_s
table
.
insert
(
table
[
"version"
]
=>
target
.
version
.
to_s
,
table
[
"migrated_at"
]
=>
Time
.
now
)
end
end
end
end
...
...
activerecord/test/cases/migration_test.rb
浏览文件 @
4e4e9ad4
...
@@ -445,6 +445,43 @@ def test_create_table_without_a_block
...
@@ -445,6 +445,43 @@ def test_create_table_without_a_block
Person
.
connection
.
drop_table
table_name
rescue
nil
Person
.
connection
.
drop_table
table_name
rescue
nil
end
end
def
test_create_table_with_custom_sequence_name
return
unless
current_adapter?
:OracleAdapter
# table name is 29 chars, the standard sequence name will
# be 33 chars and fail
assert_raise
(
ActiveRecord
::
StatementInvalid
)
do
begin
Person
.
connection
.
create_table
:table_with_name_thats_just_ok
do
|
t
|
t
.
column
:foo
,
:string
,
:null
=>
false
end
ensure
Person
.
connection
.
drop_table
:table_with_name_thats_just_ok
rescue
nil
end
end
# should be all good w/ a custom sequence name
assert_nothing_raised
do
begin
Person
.
connection
.
create_table
:table_with_name_thats_just_ok
,
:sequence_name
=>
'suitably_short_seq'
do
|
t
|
t
.
column
:foo
,
:string
,
:null
=>
false
end
Person
.
connection
.
execute
(
"select suitably_short_seq.nextval from dual"
)
ensure
Person
.
connection
.
drop_table
:table_with_name_thats_just_ok
,
:sequence_name
=>
'suitably_short_seq'
rescue
nil
end
end
# confirm the custom sequence got dropped
assert_raise
(
ActiveRecord
::
StatementInvalid
)
do
Person
.
connection
.
execute
(
"select suitably_short_seq.nextval from dual"
)
end
end
# Sybase, and SQLite3 will not allow you to add a NOT NULL
# Sybase, and SQLite3 will not allow you to add a NOT NULL
# column to a table without a default value.
# column to a table without a default value.
unless
current_adapter?
(
:SybaseAdapter
,
:SQLite3Adapter
)
unless
current_adapter?
(
:SybaseAdapter
,
:SQLite3Adapter
)
...
@@ -1462,6 +1499,17 @@ def test_schema_migrations_table_name
...
@@ -1462,6 +1499,17 @@ def test_schema_migrations_table_name
ActiveRecord
::
Base
.
table_name_suffix
=
""
ActiveRecord
::
Base
.
table_name_suffix
=
""
end
end
def
test_migration_row_includes_timestamp
conn
=
ActiveRecord
::
Base
.
connection
sm_table
=
ActiveRecord
::
Migrator
.
schema_migrations_table_name
ActiveRecord
::
Migrator
.
migrate
(
MIGRATIONS_ROOT
+
"/valid"
)
conn
.
select_all
(
"SELECT * FROM
#{
conn
.
quote_table_name
(
sm_table
)
}
"
).
each
do
|
row
|
assert_match
/^2\d\d\d-/
,
row
[
"migrated_at"
],
"missing migrated_at"
end
end
def
test_proper_table_name
def
test_proper_table_name
assert_equal
"table"
,
ActiveRecord
::
Migrator
.
proper_table_name
(
'table'
)
assert_equal
"table"
,
ActiveRecord
::
Migrator
.
proper_table_name
(
'table'
)
assert_equal
"table"
,
ActiveRecord
::
Migrator
.
proper_table_name
(
:table
)
assert_equal
"table"
,
ActiveRecord
::
Migrator
.
proper_table_name
(
:table
)
...
@@ -2117,4 +2165,3 @@ def test_copying_migrations_to_empty_directory
...
@@ -2117,4 +2165,3 @@ def test_copying_migrations_to_empty_directory
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录