Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5a47639a
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,发现更多精彩内容 >>
提交
5a47639a
编写于
10月 23, 2015
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22033 from jmccartie/jm/uuid_nil
Guard clause for id_kind in generator
上级
f94e328c
ef31d541
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
28 addition
and
19 deletion
+28
-19
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+3
-2
activerecord/lib/rails/generators/active_record/migration.rb
activerecord/lib/rails/generators/active_record/migration.rb
+7
-0
activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
...generators/active_record/migration/migration_generator.rb
+2
-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/model/model_generator.rb
...b/rails/generators/active_record/model/model_generator.rb
+5
-6
railties/lib/rails/generators/migration.rb
railties/lib/rails/generators/migration.rb
+0
-5
railties/test/generators/migration_generator_test.rb
railties/test/generators/migration_generator_test.rb
+1
-5
railties/test/generators/model_generator_test.rb
railties/test/generators/model_generator_test.rb
+9
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
5a47639a
...
...
@@ -7,8 +7,9 @@
*
Add ability to default to
`uuid`
as primary key when generating database migrations
Set `Rails.application.config.active_record.primary_key = :uuid`
or `config.active_record.primary_key = :uuid` in config/application.rb
config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
end
*Jon McCartie*
...
...
activerecord/lib/rails/generators/active_record/migration.rb
浏览文件 @
5a47639a
...
...
@@ -13,6 +13,13 @@ def next_migration_number(dirname)
ActiveRecord
::
Migration
.
next_migration_number
(
next_migration_number
)
end
end
private
def
primary_key_type
key_type
=
options
[
:primary_key_type
]
", id: :
#{
key_type
}
"
if
key_type
end
end
end
end
activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
浏览文件 @
5a47639a
...
...
@@ -5,6 +5,8 @@ module Generators # :nodoc:
class
MigrationGenerator
<
Base
# :nodoc:
argument
:attributes
,
:type
=>
:array
,
:default
=>
[],
:banner
=>
"field[:type][:index] field[:type][:index]"
class_option
:primary_key_type
,
type: :string
,
desc:
"The type for primary key"
def
create_migration_file
set_local_assigns!
validate_file_name!
...
...
activerecord/lib/rails/generators/active_record/migration/templates/create_table_migration.rb
浏览文件 @
5a47639a
class
<
%= migration_class_name %> < ActiveRecord::Migration
def change
create_table :<%=
table_name
%><%=
id_kind
%>
do
|
t
|
create_table :<%=
table_name
%><%=
primary_key_type
%>
do
|
t
|
<
% attributes.each
do
|
attribute
|
-
%>
<% if attribute.password_digest? -%>
t
.
string
:password_digest
<
%= attribute.inject_options %>
...
...
activerecord/lib/rails/generators/active_record/model/model_generator.rb
浏览文件 @
5a47639a
...
...
@@ -7,14 +7,13 @@ class ModelGenerator < Base # :nodoc:
check_class_collision
class_option
:migration
,
:type
=>
:boolean
class_option
:timestamps
,
:type
=>
:boolean
class_option
:parent
,
:type
=>
:string
,
:desc
=>
"The parent class for the generated model"
class_option
:indexes
,
:type
=>
:boolean
,
:default
=>
true
,
:desc
=>
"Add indexes for references and belongs_to columns"
class_option
:migration
,
type: :boolean
class_option
:timestamps
,
type: :boolean
class_option
:parent
,
type: :string
,
desc:
"The parent class for the generated model"
class_option
:indexes
,
type: :boolean
,
default:
true
,
desc:
"Add indexes for references and belongs_to columns"
class_option
:primary_key_type
,
type: :string
,
desc:
"The type for primary key"
# creates the migration file for the model.
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
...
...
railties/lib/rails/generators/migration.rb
浏览文件 @
5a47639a
...
...
@@ -30,11 +30,6 @@ def next_migration_number(dirname)
end
end
def
id_kind
kind
=
Rails
.
application
.
config
.
active_record
.
primary_key
rescue
nil
", id: :
#{
kind
}
"
if
kind
end
def
create_migration
(
destination
,
data
,
config
=
{},
&
block
)
action
Rails
::
Generators
::
Actions
::
CreateMigration
.
new
(
self
,
destination
,
block
||
data
.
to_s
,
config
)
end
...
...
railties/test/generators/migration_generator_test.rb
浏览文件 @
5a47639a
...
...
@@ -222,16 +222,12 @@ def test_create_table_migration
end
def
test_add_uuid_to_create_table_migration
previous_value
=
Rails
.
application
.
config
.
active_record
.
primary_key
Rails
.
application
.
config
.
active_record
.
primary_key
=
:uuid
run_generator
[
"create_books"
]
run_generator
[
"create_books"
,
"--primary_key_type=uuid"
]
assert_migration
"db/migrate/create_books.rb"
do
|
content
|
assert_method
:change
,
content
do
|
change
|
assert_match
(
/create_table :books, id: :uuid/
,
change
)
end
end
Rails
.
application
.
config
.
active_record
.
primary_key
=
previous_value
end
def
test_should_create_empty_migrations_if_name_not_start_with_add_or_remove_or_create
...
...
railties/test/generators/model_generator_test.rb
浏览文件 @
5a47639a
...
...
@@ -374,6 +374,15 @@ def test_index_is_skipped_for_references_association
end
end
def
test_add_uuid_to_create_table_migration
run_generator
[
"account"
,
"--primary_key_type=uuid"
]
assert_migration
"db/migrate/create_accounts.rb"
do
|
content
|
assert_method
:change
,
content
do
|
change
|
assert_match
(
/create_table :accounts, id: :uuid/
,
change
)
end
end
end
def
test_required_belongs_to_adds_required_association
run_generator
[
"account"
,
"supplier:references{required}"
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录