Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2f8ba24e
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,发现更多精彩内容 >>
提交
2f8ba24e
编写于
2月 01, 2016
作者:
R
Rafael França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23359 from kamipo/make_to_primary_key
Make to primary key instead of an unique index for internal tables
上级
55e33667
ff16a399
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
5 addition
and
40 deletion
+5
-40
activerecord/lib/active_record/internal_metadata.rb
activerecord/lib/active_record/internal_metadata.rb
+2
-8
activerecord/lib/active_record/schema_migration.rb
activerecord/lib/active_record/schema_migration.rb
+2
-7
activerecord/test/cases/ar_schema_test.rb
activerecord/test/cases/ar_schema_test.rb
+1
-1
activerecord/test/cases/migration/table_and_index_test.rb
activerecord/test/cases/migration/table_and_index_test.rb
+0
-24
未找到文件。
activerecord/lib/active_record/internal_metadata.rb
浏览文件 @
2f8ba24e
...
...
@@ -18,10 +18,6 @@ def table_name
"
#{
table_name_prefix
}#{
ActiveRecord
::
Base
.
internal_metadata_table_name
}#{
table_name_suffix
}
"
end
def
index_name
"
#{
table_name_prefix
}
unique_
#{
ActiveRecord
::
Base
.
internal_metadata_table_name
}#{
table_name_suffix
}
"
end
def
[]=
(
key
,
value
)
first_or_initialize
(
key:
key
).
update_attributes!
(
value:
value
)
end
...
...
@@ -38,10 +34,8 @@ def table_exists?
def
create_table
unless
table_exists?
connection
.
create_table
(
table_name
,
id:
false
)
do
|
t
|
t
.
column
:key
,
:string
,
null:
false
,
limit:
KEY_LIMIT
t
.
column
:value
,
:string
t
.
index
:key
,
unique:
true
,
name:
index_name
t
.
string
:key
,
primary_key:
true
,
limit:
KEY_LIMIT
t
.
string
:value
t
.
timestamps
end
end
...
...
activerecord/lib/active_record/schema_migration.rb
浏览文件 @
2f8ba24e
...
...
@@ -16,22 +16,17 @@ def table_name
"
#{
table_name_prefix
}#{
ActiveRecord
::
Base
.
schema_migrations_table_name
}#{
table_name_suffix
}
"
end
def
index_name
"
#{
table_name_prefix
}
unique_
#{
ActiveRecord
::
Base
.
schema_migrations_table_name
}#{
table_name_suffix
}
"
end
def
table_exists?
ActiveSupport
::
Deprecation
.
silence
{
connection
.
table_exists?
(
table_name
)
}
end
def
create_table
(
limit
=
nil
)
unless
table_exists?
version_options
=
{
null:
false
}
version_options
=
{
primary_key:
true
}
version_options
[
:limit
]
=
limit
if
limit
connection
.
create_table
(
table_name
,
id:
false
)
do
|
t
|
t
.
column
:version
,
:string
,
version_options
t
.
index
:version
,
unique:
true
,
name:
index_name
t
.
string
:version
,
version_options
end
end
end
...
...
activerecord/test/cases/ar_schema_test.rb
浏览文件 @
2f8ba24e
...
...
@@ -21,7 +21,7 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
ActiveRecord
::
Migration
.
verbose
=
@original_verbose
end
def
test_has_
has_
primary_key
def
test_has_primary_key
old_primary_key_prefix_type
=
ActiveRecord
::
Base
.
primary_key_prefix_type
ActiveRecord
::
Base
.
primary_key_prefix_type
=
:table_name_with_underscore
assert_equal
"version"
,
ActiveRecord
::
SchemaMigration
.
primary_key
...
...
activerecord/test/cases/migration/table_and_index_test.rb
已删除
100644 → 0
浏览文件 @
55e33667
require
"cases/helper"
module
ActiveRecord
class
Migration
class
TableAndIndexTest
<
ActiveRecord
::
TestCase
def
test_add_schema_info_respects_prefix_and_suffix
conn
=
ActiveRecord
::
Base
.
connection
conn
.
drop_table
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
,
if_exists:
true
)
# Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
ActiveRecord
::
Base
.
table_name_prefix
=
'p_'
ActiveRecord
::
Base
.
table_name_suffix
=
'_s'
conn
.
drop_table
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
,
if_exists:
true
)
conn
.
initialize_schema_migrations_table
assert_equal
"p_unique_schema_migrations_s"
,
conn
.
indexes
(
ActiveRecord
::
Migrator
.
schema_migrations_table_name
)[
0
][
:name
]
ensure
ActiveRecord
::
Base
.
table_name_prefix
=
""
ActiveRecord
::
Base
.
table_name_suffix
=
""
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录