Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3a0b6c8e
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,发现更多精彩内容 >>
提交
3a0b6c8e
编写于
2月 20, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9120 from hone/db_migrate_with_database_url
fix rake db:migrate when used with ENV['DATABASE_URL']
上级
ebae71a6
b1de1892
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
10 deletion
+24
-10
activerecord/lib/active_record/connection_adapters/connection_specification.rb
...ve_record/connection_adapters/connection_specification.rb
+2
-2
activerecord/lib/active_record/railtie.rb
activerecord/lib/active_record/railtie.rb
+1
-3
railties/CHANGELOG.md
railties/CHANGELOG.md
+3
-0
railties/lib/rails/application/configuration.rb
railties/lib/rails/application/configuration.rb
+6
-2
railties/test/application/rake/dbs_test.rb
railties/test/application/rake/dbs_test.rb
+12
-3
未找到文件。
activerecord/lib/active_record/connection_adapters/connection_specification.rb
浏览文件 @
3a0b6c8e
...
...
@@ -38,7 +38,7 @@ def spec
private
def
resolve_string_connection
(
spec
)
# :nodoc:
hash
=
configurations
.
fetch
(
spec
)
do
|
k
|
connection_url_to_hash
(
k
)
self
.
class
.
connection_url_to_hash
(
k
)
end
raise
(
AdapterNotSpecified
,
"
#{
spec
}
database is not configured"
)
unless
hash
...
...
@@ -69,7 +69,7 @@ def resolve_hash_connection(spec) # :nodoc:
SIMPLE_INT
=
/\A\d+\z/
SIMPLE_FLOAT
=
/\A\d+\.\d+\z/
def
connection_url_to_hash
(
url
)
# :nodoc:
def
self
.
connection_url_to_hash
(
url
)
# :nodoc:
config
=
URI
.
parse
url
adapter
=
config
.
scheme
adapter
=
"postgresql"
if
adapter
==
"postgres"
...
...
activerecord/lib/active_record/railtie.rb
浏览文件 @
3a0b6c8e
...
...
@@ -141,9 +141,7 @@ class Railtie < Rails::Railtie # :nodoc:
# and then establishes the connection.
initializer
"active_record.initialize_database"
do
|
app
|
ActiveSupport
.
on_load
(
:active_record
)
do
unless
ENV
[
'DATABASE_URL'
]
self
.
configurations
=
app
.
config
.
database_configuration
end
self
.
configurations
=
app
.
config
.
database_configuration
establish_connection
end
end
...
...
railties/CHANGELOG.md
浏览文件 @
3a0b6c8e
## Rails 4.0.0 (unreleased) ##
*
fix rake db:
*
tasks to work with DATABASE_URL and without config/database.yml
*Terence Lee*
*
Add notice message for destroy action in scaffold generator.
...
...
railties/lib/rails/application/configuration.rb
浏览文件 @
3a0b6c8e
...
...
@@ -101,8 +101,12 @@ def threadsafe!
# contents of the file are processed via ERB before being sent through
# YAML::load.
def
database_configuration
require
'erb'
YAML
.
load
ERB
.
new
(
IO
.
read
(
paths
[
"config/database"
].
first
)).
result
if
ENV
[
'DATABASE_URL'
]
{
Rails
.
env
=>
ActiveRecord
::
ConnectionAdapters
::
ConnectionSpecification
::
Resolver
.
connection_url_to_hash
(
ENV
[
'DATABASE_URL'
]).
stringify_keys
}
else
require
'erb'
YAML
.
load
ERB
.
new
(
IO
.
read
(
paths
[
"config/database"
].
first
)).
result
end
rescue
Psych
::
SyntaxError
=>
e
raise
"YAML syntax error occurred while parsing
#{
paths
[
"config/database"
].
first
}
. "
\
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. "
\
...
...
railties/test/application/rake/dbs_test.rb
浏览文件 @
3a0b6c8e
...
...
@@ -21,6 +21,8 @@ def database_url_db_name
def
set_database_url
ENV
[
'DATABASE_URL'
]
=
"sqlite3://:@localhost/
#{
database_url_db_name
}
"
# ensure it's using the DATABASE_URL
FileUtils
.
rm_rf
(
"
#{
app_path
}
/config/database.yml"
)
end
def
expected
...
...
@@ -166,9 +168,16 @@ def db_test_load_structure
end
test
'db:test:load_structure with database_url'
do
require
"
#{
app_path
}
/config/environment"
set_database_url
db_test_load_structure
old_rails_env
=
ENV
[
"RAILS_ENV"
]
ENV
[
"RAILS_ENV"
]
=
'test'
begin
require
"
#{
app_path
}
/config/environment"
set_database_url
db_test_load_structure
ensure
ENV
[
"RAILS_ENV"
]
=
old_rails_env
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录