Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
34ac46ce
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,发现更多精彩内容 >>
提交
34ac46ce
编写于
2月 06, 2013
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9203 from jaggederest/dumping_pgsql_extensions
Adding database extension support to schema.rb
上级
2f0c26bf
fba496f2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
0 deletion
+42
-0
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+6
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+9
-0
activerecord/lib/active_record/schema_dumper.rb
activerecord/lib/active_record/schema_dumper.rb
+12
-0
activerecord/test/cases/adapters/postgresql/hstore_test.rb
activerecord/test/cases/adapters/postgresql/hstore_test.rb
+5
-0
activerecord/test/cases/schema_dumper_test.rb
activerecord/test/cases/schema_dumper_test.rb
+10
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
34ac46ce
...
@@ -177,6 +177,12 @@ def supports_extensions?
...
@@ -177,6 +177,12 @@ def supports_extensions?
false
false
end
end
# A list of extensions, to be filled in by databases that
# support them (at the moment, postgresql)
def
extensions
[]
end
# QUOTING ==================================================
# QUOTING ==================================================
# Returns a bind substitution value given a +column+ and list of current
# Returns a bind substitution value given a +column+ and list of current
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
34ac46ce
...
@@ -605,6 +605,15 @@ def extension_enabled?(name)
...
@@ -605,6 +605,15 @@ def extension_enabled?(name)
end
end
end
end
def
extensions
if
supports_extensions?
res
=
exec_query
"SELECT extname from pg_extension"
,
"SCHEMA"
res
.
rows
.
map
{
|
r
|
res
.
column_types
[
'extname'
].
type_cast
r
.
first
}
else
[]
end
end
# Returns the configured supported identifier length supported by PostgreSQL
# Returns the configured supported identifier length supported by PostgreSQL
def
table_alias_length
def
table_alias_length
@table_alias_length
||=
query
(
'SHOW max_identifier_length'
,
'SCHEMA'
)[
0
][
0
].
to_i
@table_alias_length
||=
query
(
'SHOW max_identifier_length'
,
'SCHEMA'
)[
0
][
0
].
to_i
...
...
activerecord/lib/active_record/schema_dumper.rb
浏览文件 @
34ac46ce
...
@@ -24,6 +24,7 @@ def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT)
...
@@ -24,6 +24,7 @@ def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT)
def
dump
(
stream
)
def
dump
(
stream
)
header
(
stream
)
header
(
stream
)
extensions
(
stream
)
tables
(
stream
)
tables
(
stream
)
trailer
(
stream
)
trailer
(
stream
)
stream
stream
...
@@ -66,6 +67,17 @@ def trailer(stream)
...
@@ -66,6 +67,17 @@ def trailer(stream)
stream
.
puts
"end"
stream
.
puts
"end"
end
end
def
extensions
(
stream
)
return
unless
@connection
.
supports_extensions?
extensions
=
@connection
.
extensions
stream
.
puts
<<
EXTENSIONS
# These are extensions that must be enabled in order to support this database
EXTENSIONS
extensions
.
each
do
|
extension
|
stream
.
puts
" enable_extension
#{
extension
.
inspect
}
"
end
end
def
tables
(
stream
)
def
tables
(
stream
)
@connection
.
tables
.
sort
.
each
do
|
tbl
|
@connection
.
tables
.
sort
.
each
do
|
tbl
|
next
if
[
'schema_migrations'
,
ignore_tables
].
flatten
.
any?
do
|
ignored
|
next
if
[
'schema_migrations'
,
ignore_tables
].
flatten
.
any?
do
|
ignored
|
...
...
activerecord/test/cases/adapters/postgresql/hstore_test.rb
浏览文件 @
34ac46ce
...
@@ -35,6 +35,11 @@ def teardown
...
@@ -35,6 +35,11 @@ def teardown
@connection
.
execute
'drop table if exists hstores'
@connection
.
execute
'drop table if exists hstores'
end
end
def
test_hstore_included_in_extensions
assert
@connection
.
respond_to?
(
:extensions
),
"connection should have a list of extensions"
assert
@connection
.
extensions
.
include?
(
'hstore'
),
"extension list should include hstore"
end
def
test_hstore_enabled
def
test_hstore_enabled
assert
@connection
.
extension_enabled?
(
'hstore'
)
assert
@connection
.
extension_enabled?
(
'hstore'
)
end
end
...
...
activerecord/test/cases/schema_dumper_test.rb
浏览文件 @
34ac46ce
...
@@ -231,6 +231,16 @@ def test_schema_dump_includes_decimal_options
...
@@ -231,6 +231,16 @@ def test_schema_dump_includes_decimal_options
end
end
if
current_adapter?
(
:PostgreSQLAdapter
)
if
current_adapter?
(
:PostgreSQLAdapter
)
def
test_schema_dump_includes_extensions
connection
=
ActiveRecord
::
Base
.
connection
return
skip
unless
connection
.
supports_extensions?
unless
connection
.
extension_enabled?
(
'hstore'
)
connection
.
enable_extension
'hstore'
end
output
=
standard_dump
assert_match
%r{enable_extension "hstore"}
,
output
end
def
test_schema_dump_includes_xml_shorthand_definition
def
test_schema_dump_includes_xml_shorthand_definition
output
=
standard_dump
output
=
standard_dump
if
%r{create_table "postgresql_xml_data_type"}
=~
output
if
%r{create_table "postgresql_xml_data_type"}
=~
output
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录