Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
249f71a2
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,发现更多精彩内容 >>
未验证
提交
249f71a2
编写于
12月 29, 2016
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Raises when `ActiveRecord::Migration` is inherited directly.
上级
bc6c5df4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
54 deletion
+35
-54
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+4
-1
activerecord/lib/active_record/migration/compatibility.rb
activerecord/lib/active_record/migration/compatibility.rb
+21
-41
activerecord/test/cases/migration/compatibility_test.rb
activerecord/test/cases/migration/compatibility_test.rb
+6
-12
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
249f71a2
*
Raises when
`ActiveRecord::Migration`
is inherited directly.
*Rafael Mendonça França*
*
Remove deprecated
`original_exception`
argument in
`ActiveRecord::StatementInvalid#initialize`
and
`ActiveRecord::StatementInvalid#original_exception`
.
...
...
activerecord/lib/active_record/migration.rb
浏览文件 @
249f71a2
...
...
@@ -522,7 +522,10 @@ class Current < Migration # :nodoc:
def
self
.
inherited
(
subclass
)
# :nodoc:
super
if
subclass
.
superclass
==
Migration
subclass
.
include
Compatibility
::
Legacy
raise
StandardError
,
"Directly inheriting from ActiveRecord::Migration is not supported. "
\
"Please specify the Rails release the migration was written for:
\n
"
\
"
\n
"
\
" class
#{
self
.
class
.
name
}
< ActiveRecord::Migration[4.2]"
end
end
...
...
activerecord/lib/active_record/migration/compatibility.rb
浏览文件 @
249f71a2
...
...
@@ -13,7 +13,27 @@ def self.find(version)
V5_1
=
Current
module
FourTwoShared
class
V5_0
<
V5_1
def
create_table
(
table_name
,
options
=
{})
if
adapter_name
==
"PostgreSQL"
if
options
[
:id
]
==
:uuid
&&
!
options
[
:default
]
options
[
:default
]
=
"uuid_generate_v4()"
end
end
# Since 5.1 Postgres adapter uses bigserial type for primary
# keys by default and MySQL uses bigint. This compat layer makes old migrations utilize
# serial/int type instead -- the way it used to work before 5.1.
if
options
[
:id
].
blank?
options
[
:id
]
=
:integer
options
[
:auto_increment
]
=
true
end
super
end
end
class
V4_2
<
V5_0
module
TableDefinition
def
references
(
*
,
**
options
)
options
[
:index
]
||=
false
...
...
@@ -101,46 +121,6 @@ def index_name_for_remove(table_name, options = {})
index_name
end
end
class
V5_0
<
V5_1
def
create_table
(
table_name
,
options
=
{})
if
adapter_name
==
"PostgreSQL"
if
options
[
:id
]
==
:uuid
&&
!
options
[
:default
]
options
[
:default
]
=
"uuid_generate_v4()"
end
end
# Since 5.1 Postgres adapter uses bigserial type for primary
# keys by default and MySQL uses bigint. This compat layer makes old migrations utilize
# serial/int type instead -- the way it used to work before 5.1.
if
options
[
:id
].
blank?
options
[
:id
]
=
:integer
options
[
:auto_increment
]
=
true
end
super
end
end
class
V4_2
<
V5_0
# 4.2 is defined as a module because it needs to be shared with
# Legacy. When the time comes, V5_0 should be defined straight
# in its class.
include
FourTwoShared
end
module
Legacy
include
FourTwoShared
def
migrate
(
*
)
ActiveSupport
::
Deprecation
.
warn
\
"Directly inheriting from ActiveRecord::Migration is deprecated. "
\
"Please specify the Rails release the migration was written for:
\n
"
\
"
\n
"
\
" class
#{
self
.
class
.
name
}
< ActiveRecord::Migration[4.2]"
super
end
end
end
end
end
activerecord/test/cases/migration/compatibility_test.rb
浏览文件 @
249f71a2
...
...
@@ -55,7 +55,7 @@ def migrate(x)
end
def
test_references_does_not_add_index_by_default
migration
=
Class
.
new
(
ActiveRecord
::
Migration
)
{
migration
=
Class
.
new
(
ActiveRecord
::
Migration
[
4.2
]
)
{
def
migrate
(
x
)
create_table
:more_testings
do
|
t
|
t
.
references
:foo
...
...
@@ -73,7 +73,7 @@ def migrate(x)
end
def
test_timestamps_have_null_constraints_if_not_present_in_migration_of_create_table
migration
=
Class
.
new
(
ActiveRecord
::
Migration
)
{
migration
=
Class
.
new
(
ActiveRecord
::
Migration
[
4.2
]
)
{
def
migrate
(
x
)
create_table
:more_testings
do
|
t
|
t
.
timestamps
...
...
@@ -90,7 +90,7 @@ def migrate(x)
end
def
test_timestamps_have_null_constraints_if_not_present_in_migration_for_adding_timestamps_to_existing_table
migration
=
Class
.
new
(
ActiveRecord
::
Migration
)
{
migration
=
Class
.
new
(
ActiveRecord
::
Migration
[
4.2
]
)
{
def
migrate
(
x
)
add_timestamps
:testings
end
...
...
@@ -102,15 +102,9 @@ def migrate(x)
assert
connection
.
columns
(
:testings
).
find
{
|
c
|
c
.
name
==
"updated_at"
}.
null
end
def
test_legacy_migrations_get_deprecation_warning_when_run
migration
=
Class
.
new
(
ActiveRecord
::
Migration
)
{
def
up
add_column
:testings
,
:baz
,
:string
end
}
assert_deprecated
do
migration
.
migrate
:up
def
test_legacy_migrations_raises_exception_when_inherited
assert_raises
(
StandardError
)
do
Class
.
new
(
ActiveRecord
::
Migration
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录