Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
12e9a75f
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 搜索 >>
提交
12e9a75f
编写于
6月 12, 2012
作者:
K
Konstantin Shabanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add uuid type support to PostgreSQL adapter
上级
122f6de2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
10 deletion
+39
-10
activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
...d/lib/active_record/connection_adapters/postgresql/oid.rb
+1
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+7
-3
activerecord/test/cases/adapters/postgresql/datatype_test.rb
activerecord/test/cases/adapters/postgresql/datatype_test.rb
+15
-0
activerecord/test/cases/column_definition_test.rb
activerecord/test/cases/column_definition_test.rb
+0
-6
activerecord/test/cases/schema_dumper_test.rb
activerecord/test/cases/schema_dumper_test.rb
+7
-0
activerecord/test/schema/postgresql_specific_schema.rb
activerecord/test/schema/postgresql_specific_schema.rb
+9
-1
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
浏览文件 @
12e9a75f
...
...
@@ -223,6 +223,7 @@ def self.registered_type?(name)
alias_type
'bit'
,
'text'
alias_type
'varbit'
,
'text'
alias_type
'macaddr'
,
'text'
alias_type
'uuid'
,
'text'
# FIXME: I don't think this is correct. We should probably be returning a parsed date,
# but the tests pass with a string returned.
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
12e9a75f
...
...
@@ -89,7 +89,6 @@ def string_to_cidr(string)
else
string
end
end
def
cidr_to_string
(
object
)
...
...
@@ -256,7 +255,7 @@ def simplified_type(field_type)
:integer
# UUID type
when
'uuid'
:
string
:
uuid
# Small and big integer types
when
/^(?:small|big)int$/
:integer
...
...
@@ -319,6 +318,10 @@ def cidr(name, options = {})
def
macaddr
(
name
,
options
=
{})
column
(
name
,
'macaddr'
,
options
)
end
def
uuid
(
name
,
options
=
{})
column
(
name
,
'uuid'
,
options
)
end
end
ADAPTER_NAME
=
'PostgreSQL'
...
...
@@ -341,7 +344,8 @@ def macaddr(name, options = {})
:hstore
=>
{
:name
=>
"hstore"
},
:inet
=>
{
:name
=>
"inet"
},
:cidr
=>
{
:name
=>
"cidr"
},
:macaddr
=>
{
:name
=>
"macaddr"
}
:macaddr
=>
{
:name
=>
"macaddr"
},
:uuid
=>
{
:name
=>
"uuid"
}
}
# Returns 'PostgreSQL' as adapter name for identification purposes.
...
...
activerecord/test/cases/adapters/postgresql/datatype_test.rb
浏览文件 @
12e9a75f
...
...
@@ -27,6 +27,9 @@ class PostgresqlOid < ActiveRecord::Base
class
PostgresqlTimestampWithZone
<
ActiveRecord
::
Base
end
class
PostgresqlUUID
<
ActiveRecord
::
Base
end
class
PostgresqlDataTypeTest
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
...
...
@@ -61,6 +64,9 @@ def setup
@first_oid
=
PostgresqlOid
.
find
(
1
)
@connection
.
execute
(
"INSERT INTO postgresql_timestamp_with_zones (time) VALUES ('2010-01-01 10:00:00-1')"
)
@connection
.
execute
(
"INSERT INTO postgresql_uuids (guid, compact_guid) VALUES('d96c3da0-96c1-012f-1316-64ce8f32c6d8', 'f06c715096c1012f131764ce8f32c6d8')"
)
@first_uuid
=
PostgresqlUUID
.
find
(
1
)
end
def
test_data_type_of_array_types
...
...
@@ -100,6 +106,10 @@ def test_data_type_of_oid_types
assert_equal
:integer
,
@first_oid
.
column_for_attribute
(
:obj_id
).
type
end
def
test_data_type_of_uuid_types
assert_equal
:uuid
,
@first_uuid
.
column_for_attribute
(
:guid
).
type
end
def
test_array_values
assert_equal
'{35000,21000,18000,17000}'
,
@first_array
.
commission_by_quarter
assert_equal
'{foo,bar,baz}'
,
@first_array
.
nicknames
...
...
@@ -143,6 +153,11 @@ def test_network_address_values_ipaddr
assert_equal
'01:23:45:67:89:0a'
,
@first_network_address
.
mac_address
end
def
test_uuid_values
assert_equal
'd96c3da0-96c1-012f-1316-64ce8f32c6d8'
,
@first_uuid
.
guid
assert_equal
'f06c7150-96c1-012f-1317-64ce8f32c6d8'
,
@first_uuid
.
compact_guid
end
def
test_bit_string_values
assert_equal
'00010101'
,
@first_bit_string
.
bit_string
assert_equal
'00010101'
,
@first_bit_string
.
bit_string_varying
...
...
activerecord/test/cases/column_definition_test.rb
浏览文件 @
12e9a75f
...
...
@@ -136,12 +136,6 @@ def test_smallint_column_should_map_to_integer
smallint_column
=
PostgreSQLColumn
.
new
(
'number'
,
nil
,
oid
,
"smallint"
)
assert_equal
:integer
,
smallint_column
.
type
end
def
test_uuid_column_should_map_to_string
oid
=
PostgreSQLAdapter
::
OID
::
Identity
.
new
uuid_column
=
PostgreSQLColumn
.
new
(
'unique_id'
,
nil
,
oid
,
"uuid"
)
assert_equal
:string
,
uuid_column
.
type
end
end
end
end
...
...
activerecord/test/cases/schema_dumper_test.rb
浏览文件 @
12e9a75f
...
...
@@ -257,6 +257,13 @@ def test_schema_dump_includes_macaddr_shorthand_definition
end
end
def
test_schema_dump_includes_uuid_shorthand_definition
output
=
standard_dump
if
%r{create_table "poistgresql_uuids"}
=~
output
assert_match
%r{t.uuid "guid"}
,
output
end
end
def
test_schema_dump_includes_hstores_shorthand_definition
output
=
standard_dump
if
%r{create_table "postgresql_hstores"}
=~
output
...
...
activerecord/test/schema/postgresql_specific_schema.rb
浏览文件 @
12e9a75f
ActiveRecord
::
Schema
.
define
do
%w(postgresql_tsvectors postgresql_hstores postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times postgresql_network_addresses postgresql_bit_strings
%w(postgresql_tsvectors postgresql_hstores postgresql_arrays postgresql_moneys postgresql_numbers postgresql_times postgresql_network_addresses postgresql_bit_strings
postgresql_uuids
postgresql_oids postgresql_xml_data_type defaults geometrics postgresql_timestamp_with_zones postgresql_partitioned_table postgresql_partitioned_table_parent)
.
each
do
|
table_name
|
execute
"DROP TABLE IF EXISTS
#{
quote_table_name
table_name
}
"
end
...
...
@@ -58,6 +58,14 @@
);
_SQL
execute
<<
_SQL
CREATE TABLE postgresql_uuids (
id SERIAL PRIMARY KEY,
guid uuid,
compact_guid uuid
);
_SQL
execute
<<
_SQL
CREATE TABLE postgresql_tsvectors (
id SERIAL PRIMARY KEY,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录