Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6fa6c739
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 搜索 >>
提交
6fa6c739
编写于
3月 03, 2015
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correctly dump `serial` and `bigserial`
上级
5366cc6b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
93 addition
and
4 deletion
+93
-4
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
...tive_record/connection_adapters/abstract/schema_dumper.rb
+5
-1
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+1
-1
activerecord/lib/active_record/connection_adapters/postgresql/column.rb
...ib/active_record/connection_adapters/postgresql/column.rb
+3
-1
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+20
-1
activerecord/test/cases/adapters/postgresql/serial_test.rb
activerecord/test/cases/adapters/postgresql/serial_test.rb
+60
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
6fa6c739
*
Correctly dump
`serial`
and
`bigserial`
.
*Ryuta Kamizono*
*
Fix default
`format`
value in
`ActiveRecord::Tasks::DatabaseTasks#schema_file`
.
*James Cox*
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_dumper.rb
浏览文件 @
6fa6c739
...
...
@@ -24,7 +24,7 @@ def column_spec_for_primary_key(column)
def
prepare_column_options
(
column
)
spec
=
{}
spec
[
:name
]
=
column
.
name
.
inspect
spec
[
:type
]
=
column
.
type
.
to_s
spec
[
:type
]
=
schema_type
(
column
)
spec
[
:null
]
=
'false'
unless
column
.
null
limit
=
column
.
limit
||
native_database_types
[
column
.
type
][
:limit
]
...
...
@@ -45,6 +45,10 @@ def migration_keys
private
def
schema_type
(
column
)
column
.
type
.
to_s
end
def
schema_default
(
column
)
type
=
lookup_cast_type_from_column
(
column
)
default
=
type
.
deserialize
(
column
.
default
)
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
6fa6c739
...
...
@@ -31,7 +31,7 @@ def initialize(name, default, sql_type_metadata = nil, null = true, default_func
end
def
has_default?
!
default
.
nil?
!
default
.
nil?
||
default_function
end
def
bigint?
...
...
activerecord/lib/active_record/connection_adapters/postgresql/column.rb
浏览文件 @
6fa6c739
...
...
@@ -6,7 +6,9 @@ class PostgreSQLColumn < Column #:nodoc:
alias
:array?
:array
def
serial?
default_function
&&
default_function
=~
/\Anextval\(.*\)\z/
return
unless
default_function
%r{
\A
nextval
\(
'(?<table_name>.+)_
#{
name
}
_seq'::regclass
\)\z
}
===
default_function
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
6fa6c739
...
...
@@ -145,7 +145,6 @@ def column_spec_for_primary_key(column)
def
prepare_column_options
(
column
)
# :nodoc:
spec
=
super
spec
[
:array
]
=
'true'
if
column
.
array?
spec
[
:default
]
=
"
\"
#{
column
.
default_function
}
\"
"
if
column
.
default_function
spec
end
...
...
@@ -154,6 +153,26 @@ def migration_keys
super
+
[
:array
]
end
def
schema_type
(
column
)
return
super
unless
column
.
serial?
if
column
.
bigint?
'bigserial'
else
'serial'
end
end
private
:schema_type
def
schema_default
(
column
)
if
column
.
default_function
column
.
default_function
.
inspect
unless
column
.
serial?
else
super
end
end
private
:schema_default
# Returns +true+, since this connection adapter supports prepared statement
# caching.
def
supports_statement_cache?
...
...
activerecord/test/cases/adapters/postgresql/serial_test.rb
0 → 100644
浏览文件 @
6fa6c739
require
"cases/helper"
require
'support/schema_dumping_helper'
class
PostgresqlSerialTest
<
ActiveRecord
::
TestCase
include
SchemaDumpingHelper
class
PostgresqlSerial
<
ActiveRecord
::
Base
;
end
setup
do
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
create_table
"postgresql_serials"
,
force:
true
do
|
t
|
t
.
serial
:seq
end
end
teardown
do
@connection
.
drop_table
"postgresql_serials"
,
if_exists:
true
end
def
test_serial_column
column
=
PostgresqlSerial
.
columns_hash
[
"seq"
]
assert_equal
:integer
,
column
.
type
assert_equal
"integer"
,
column
.
sql_type
assert
column
.
serial?
end
def
test_schema_dump_with_shorthand
output
=
dump_table_schema
"postgresql_serials"
assert_match
%r{t
\.
serial
\s
+"seq"}
,
output
end
end
class
PostgresqlBigSerialTest
<
ActiveRecord
::
TestCase
include
SchemaDumpingHelper
class
PostgresqlBigSerial
<
ActiveRecord
::
Base
;
end
setup
do
@connection
=
ActiveRecord
::
Base
.
connection
@connection
.
create_table
"postgresql_big_serials"
,
force:
true
do
|
t
|
t
.
bigserial
:seq
end
end
teardown
do
@connection
.
drop_table
"postgresql_big_serials"
,
if_exists:
true
end
def
test_bigserial_column
column
=
PostgresqlBigSerial
.
columns_hash
[
"seq"
]
assert_equal
:integer
,
column
.
type
assert_equal
"bigint"
,
column
.
sql_type
assert
column
.
serial?
end
def
test_schema_dump_with_shorthand
output
=
dump_table_schema
"postgresql_big_serials"
assert_match
%r{t
\.
bigserial
\s
+"seq"}
,
output
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录