Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
42ed16a9
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 搜索 >>
未验证
提交
42ed16a9
编写于
2月 13, 2017
作者:
R
Ryuta Kamizono
提交者:
Jeremy Daer
2月 12, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Schema dumping support for PostgreSQL interval type
Closes #27979
上级
bb45fa05
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
36 addition
and
21 deletion
+36
-21
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
..._record/connection_adapters/abstract/schema_statements.rb
+1
-1
activerecord/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
.../connection_adapters/postgresql/oid/specialized_string.rb
+2
-1
activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb
...cord/connection_adapters/postgresql/schema_definitions.rb
+4
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+5
-2
activerecord/test/cases/adapters/postgresql/datatype_test.rb
activerecord/test/cases/adapters/postgresql/datatype_test.rb
+2
-2
activerecord/test/cases/schema_dumper_test.rb
activerecord/test/cases/schema_dumper_test.rb
+10
-4
activerecord/test/schema/postgresql_specific_schema.rb
activerecord/test/schema/postgresql_specific_schema.rb
+8
-11
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
42ed16a9
*
PostgreSQL: schema dumping support for PostgreSQL interval type.
*Ryuta Kamizono*
*
Deprecate
`supports_primary_key?`
on connection adapters since it's
been long unused and unsupported.
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
浏览文件 @
42ed16a9
...
...
@@ -1070,7 +1070,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) # :nodoc:
raise
ArgumentError
,
"Error adding decimal column: precision cannot be empty if scale is specified"
end
elsif
[
:datetime
,
:time
].
include?
(
type
)
&&
precision
||=
native
[
:precision
]
elsif
[
:datetime
,
:time
,
:interval
].
include?
(
type
)
&&
precision
||=
native
[
:precision
]
if
(
0
..
6
)
===
precision
column_type_sql
<<
"(
#{
precision
}
)"
else
...
...
activerecord/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb
浏览文件 @
42ed16a9
...
...
@@ -5,8 +5,9 @@ module OID # :nodoc:
class
SpecializedString
<
Type
::
String
# :nodoc:
attr_reader
:type
def
initialize
(
type
)
def
initialize
(
type
,
**
options
)
@type
=
type
super
(
options
)
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb
浏览文件 @
42ed16a9
...
...
@@ -88,6 +88,10 @@ def inet(*args, **options)
args
.
each
{
|
name
|
column
(
name
,
:inet
,
options
)
}
end
def
interval
(
*
args
,
**
options
)
args
.
each
{
|
name
|
column
(
name
,
:interval
,
options
)
}
end
def
int4range
(
*
args
,
**
options
)
args
.
each
{
|
name
|
column
(
name
,
:int4range
,
options
)
}
end
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
42ed16a9
...
...
@@ -109,6 +109,7 @@ class PostgreSQLAdapter < AbstractAdapter
bit:
{
name:
"bit"
},
bit_varying:
{
name:
"bit varying"
},
money:
{
name:
"money"
},
interval:
{
name:
"interval"
},
}
OID
=
PostgreSQL
::
OID
#:nodoc:
...
...
@@ -486,8 +487,10 @@ def initialize_type_map(m)
m
.
register_type
"polygon"
,
OID
::
SpecializedString
.
new
(
:polygon
)
m
.
register_type
"circle"
,
OID
::
SpecializedString
.
new
(
:circle
)
# FIXME: why are we keeping these types as strings?
m
.
alias_type
"interval"
,
"varchar"
m
.
register_type
"interval"
do
|
_
,
_
,
sql_type
|
precision
=
extract_precision
(
sql_type
)
OID
::
SpecializedString
.
new
(
:interval
,
precision:
precision
)
end
register_class_with_precision
m
,
"time"
,
Type
::
Time
register_class_with_precision
m
,
"timestamp"
,
OID
::
DateTime
...
...
activerecord/test/cases/adapters/postgresql/datatype_test.rb
浏览文件 @
42ed16a9
...
...
@@ -28,8 +28,8 @@ def setup
end
def
test_data_type_of_time_types
assert_equal
:
string
,
@first_time
.
column_for_attribute
(
:time_interval
).
type
assert_equal
:
string
,
@first_time
.
column_for_attribute
(
:scaled_time_interval
).
type
assert_equal
:
interval
,
@first_time
.
column_for_attribute
(
:time_interval
).
type
assert_equal
:
interval
,
@first_time
.
column_for_attribute
(
:scaled_time_interval
).
type
end
def
test_data_type_of_oid_types
...
...
activerecord/test/cases/schema_dumper_test.rb
浏览文件 @
42ed16a9
...
...
@@ -261,25 +261,31 @@ def test_schema_dump_includes_decimal_options
if
current_adapter?
(
:PostgreSQLAdapter
)
def
test_schema_dump_includes_bigint_default
output
=
standard_dump
output
=
dump_table_schema
"defaults"
assert_match
%r{t
\.
bigint
\s
+"bigint_default",
\s
+default: 0}
,
output
end
def
test_schema_dump_includes_limit_on_array_type
output
=
standard_dump
output
=
dump_table_schema
"bigint_array"
assert_match
%r{t
\.
bigint
\s
+"big_int_data_points
\"
,
\s
+array: true}
,
output
end
def
test_schema_dump_allows_array_of_decimal_defaults
output
=
standard_dump
output
=
dump_table_schema
"bigint_array"
assert_match
%r{t
\.
decimal
\s
+"decimal_array_default",
\s
+default:
\[
"1.23", "3.45"
\]
,
\s
+array: true}
,
output
end
def
test_schema_dump_expression_indices
index_definition
=
standard_dump
.
split
(
/\n/
).
grep
(
/t\.index.*company_expression_index/
).
first
.
strip
index_definition
=
dump_table_schema
(
"companies"
)
.
split
(
/\n/
).
grep
(
/t\.index.*company_expression_index/
).
first
.
strip
assert_equal
't.index "lower((name)::text)", name: "company_expression_index", using: :btree'
,
index_definition
end
def
test_schema_dump_interval_type
output
=
dump_table_schema
"postgresql_times"
assert_match
%r{t
\.
interval
\s
+"time_interval"$}
,
output
assert_match
%r{t
\.
interval
\s
+"scaled_time_interval",
\s
+precision: 6$}
,
output
end
if
ActiveRecord
::
Base
.
connection
.
supports_extensions?
def
test_schema_dump_includes_extensions
connection
=
ActiveRecord
::
Base
.
connection
...
...
activerecord/test/schema/postgresql_specific_schema.rb
浏览文件 @
42ed16a9
...
...
@@ -23,12 +23,17 @@
t
.
string
:char2
,
limit:
50
,
default:
"a varchar field"
t
.
text
:char3
,
default:
"a text field"
t
.
bigint
:bigint_default
,
default:
->
{
"0::bigint"
}
t
.
text
:multiline_default
,
default:
'
--- []
t
.
text
:multiline_default
,
default:
"
--- []
'
"
end
%w(postgresql_times postgresql_oids postgresql_timestamp_with_zones
create_table
:postgresql_times
,
force:
true
do
|
t
|
t
.
interval
:time_interval
t
.
interval
:scaled_time_interval
,
precision:
6
end
%w(postgresql_oids postgresql_timestamp_with_zones
postgresql_partitioned_table postgresql_partitioned_table_parent)
.
each
do
|
table_name
|
drop_table
table_name
,
if_exists:
true
end
...
...
@@ -44,14 +49,6 @@
execute
"SELECT setval('
#{
seq_name
}
', 100)"
end
execute
<<
_SQL
CREATE TABLE postgresql_times (
id SERIAL PRIMARY KEY,
time_interval INTERVAL,
scaled_time_interval INTERVAL(6)
);
_SQL
execute
<<
_SQL
CREATE TABLE postgresql_oids (
id SERIAL PRIMARY KEY,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录