Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c942361a
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,发现更多精彩内容 >>
未验证
提交
c942361a
编写于
1月 13, 2017
作者:
K
Kevin Glowacz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generate migrations at path set by `config.paths["db/migrate"]`
上级
c8e92f17
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
2 deletion
+42
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
...generators/active_record/migration/migration_generator.rb
+9
-1
activerecord/lib/rails/generators/active_record/model/model_generator.rb
...b/rails/generators/active_record/model/model_generator.rb
+9
-1
railties/test/generators/migration_generator_test.rb
railties/test/generators/migration_generator_test.rb
+10
-0
railties/test/generators/model_generator_test.rb
railties/test/generators/model_generator_test.rb
+10
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
c942361a
*
Place generated migrations into the path set by
`config.paths["db/migrate"]`
*Kevin Glowacz*
*
Raise
`ActiveRecord::InvalidForeignKey`
when a foreign key constraint fails on Sqlite3.
*Ryuta Kamizono*
...
...
activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
浏览文件 @
c942361a
...
...
@@ -10,7 +10,7 @@ class MigrationGenerator < Base # :nodoc:
def
create_migration_file
set_local_assigns!
validate_file_name!
migration_template
@migration_template
,
"db/migrate/
#{
file_name
}
.rb"
migration_template
@migration_template
,
File
.
join
(
db_migrate_path
,
"
#{
file_name
}
.rb"
)
end
# TODO Change this to private once we've dropped Ruby 2.2 support.
...
...
@@ -71,6 +71,14 @@ def validate_file_name!
def
normalize_table_name
(
_table_name
)
pluralize_table_names?
?
_table_name
.
pluralize
:
_table_name
.
singularize
end
def
db_migrate_path
if
defined?
(
Rails
)
&&
Rails
.
application
Rails
.
application
.
config
.
paths
[
"db/migrate"
].
to_ary
.
first
else
"db/migrate"
end
end
end
end
end
activerecord/lib/rails/generators/active_record/model/model_generator.rb
浏览文件 @
c942361a
...
...
@@ -17,7 +17,7 @@ class ModelGenerator < Base # :nodoc:
def
create_migration_file
return
unless
options
[
:migration
]
&&
options
[
:parent
].
nil?
attributes
.
each
{
|
a
|
a
.
attr_options
.
delete
(
:index
)
if
a
.
reference?
&&
!
a
.
has_index?
}
if
options
[
:indexes
]
==
false
migration_template
"../../migration/templates/create_table_migration.rb"
,
"db/migrate/create_
#{
table_name
}
.rb"
migration_template
"../../migration/templates/create_table_migration.rb"
,
File
.
join
(
db_migrate_path
,
"create_
#{
table_name
}
.rb"
)
end
def
create_model_file
...
...
@@ -64,6 +64,14 @@ def application_record_file_name
"app/models/application_record.rb"
end
end
def
db_migrate_path
if
defined?
(
Rails
)
&&
Rails
.
application
Rails
.
application
.
config
.
paths
[
"db/migrate"
].
to_ary
.
first
else
"db/migrate"
end
end
end
end
end
railties/test/generators/migration_generator_test.rb
浏览文件 @
c942361a
...
...
@@ -309,6 +309,16 @@ def test_add_migration_with_token_option
end
end
def
test_add_migration_to_configured_path
old_paths
=
Rails
.
application
.
config
.
paths
[
"db/migrate"
]
Rails
.
application
.
config
.
paths
.
add
"db/migrate"
,
with:
"db2/migrate"
migration
=
"migration_in_custom_path"
run_generator
[
migration
]
Rails
.
application
.
config
.
paths
[
"db/migrate"
]
=
old_paths
assert_migration
"db2/migrate/
#{
migration
}
.rb"
,
/.*/
end
private
def
with_singular_table_name
...
...
railties/test/generators/model_generator_test.rb
浏览文件 @
c942361a
...
...
@@ -220,6 +220,16 @@ def test_migration_without_timestamps
ActiveRecord
::
Base
.
timestamped_migrations
=
true
end
def
test_migration_with_configured_path
old_paths
=
Rails
.
application
.
config
.
paths
[
"db/migrate"
]
Rails
.
application
.
config
.
paths
.
add
"db/migrate"
,
with:
"db2/migrate"
run_generator
Rails
.
application
.
config
.
paths
[
"db/migrate"
]
=
old_paths
assert_migration
"db2/migrate/create_accounts.rb"
,
/class CreateAccounts < ActiveRecord::Migration\[[0-9.]+\]/
end
def
test_model_with_references_attribute_generates_belongs_to_associations
run_generator
[
"product"
,
"name:string"
,
"supplier:references"
]
assert_file
"app/models/product.rb"
,
/belongs_to :supplier/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录