Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6940dc86
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,体验更适合开发者的 AI 搜索 >>
提交
6940dc86
编写于
12月 06, 2015
作者:
M
Matthew Draper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add migration versioning via Migration subclasses
上级
de213520
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
2 deletion
+64
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+6
-0
activerecord/lib/active_record/migration.rb
activerecord/lib/active_record/migration.rb
+26
-0
activerecord/lib/active_record/migration/compatibility.rb
activerecord/lib/active_record/migration/compatibility.rb
+30
-0
activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb
...tive_record/migration/templates/create_table_migration.rb
+1
-1
activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
...generators/active_record/migration/templates/migration.rb
+1
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
6940dc86
*
Version the API presented to migration classes, so we can change parameter
defaults without breaking existing migrations, or forcing them to be
rewritten through a deprecation cycle.
*Matthew Draper*, *Ravil Bayramgalin*
*
Use bind params for
`limit`
and
`offset`
. This will generate significantly
fewer prepared statements for common tasks like pagination. To support this
change, passing a string containing a comma to
`limit`
has been deprecated,
...
...
activerecord/lib/active_record/migration.rb
浏览文件 @
6940dc86
...
...
@@ -476,6 +476,32 @@ def initialize(message = DEFAULT_MESSAGE)
# are in a Migration with <tt>self.disable_ddl_transaction!</tt>.
class
Migration
autoload
:CommandRecorder
,
'active_record/migration/command_recorder'
autoload
:Compatibility
,
'active_record/migration/compatibility'
# This must be defined before the inherited hook, below
class
Current
<
Migration
# :nodoc:
end
def
self
.
inherited
(
subclass
)
# :nodoc:
super
if
subclass
.
superclass
==
Migration
subclass
.
include
Compatibility
::
Legacy
end
end
def
self
.
[]
(
version
)
version
=
version
.
to_s
name
=
"V
#{
version
.
tr
(
'.'
,
'_'
)
}
"
unless
Compatibility
.
const_defined?
(
name
)
versions
=
Compatibility
.
constants
.
grep
(
/\AV[0-9_]+\z/
).
map
{
|
s
|
s
.
to_s
.
delete
(
'V'
).
tr
(
'_'
,
'.'
).
inspect
}
raise
"Unknown migration version
#{
version
.
inspect
}
; expected one of
#{
versions
.
sort
.
join
(
', '
)
}
"
end
Compatibility
.
const_get
(
name
)
end
def
self
.
current_version
Rails
.
version
.
to_f
end
MigrationFilenameRegexp
=
/\A([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/
# :nodoc:
...
...
activerecord/lib/active_record/migration/compatibility.rb
0 → 100644
浏览文件 @
6940dc86
module
ActiveRecord
class
Migration
module
Compatibility
# :nodoc: all
V5_0
=
Current
module
FourTwoShared
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
run
(
*
)
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/lib/rails/generators/active_record/migration/templates/create_table_migration.rb
浏览文件 @
6940dc86
class
<
%= migration_class_name %> < ActiveRecord::Migration
class
<
%= migration_class_name %> < ActiveRecord::Migration
[<%=
ActiveRecord
::
Migration
.
current_version
%>]
def change
create_table :<%= table_name %>
<
%= primary_key_type %> do |t|
<% attributes.each do |attribute| -%>
...
...
activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
浏览文件 @
6940dc86
class
<
%= migration_class_name %> < ActiveRecord::Migration
class
<
%= migration_class_name %> < ActiveRecord::Migration
[<%=
ActiveRecord
::
Migration
.
current_version
%>]
<%- if migration_action == 'add' -%>
def
change
<
% attributes.each
do
|
attribute
|
-
%>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录