Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f4f496df
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,发现更多精彩内容 >>
提交
f4f496df
编写于
12月 23, 2013
作者:
Y
Yves Senn
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13427 from schneems/schneems/cannot-connect-postgres-error
Tell how to Create a Database in Error Message
上级
b4d7be95
0ec45cd1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
0 deletion
+40
-0
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+7
-0
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+6
-0
activerecord/lib/active_record/errors.rb
activerecord/lib/active_record/errors.rb
+12
-0
activerecord/lib/active_record/railtie.rb
activerecord/lib/active_record/railtie.rb
+8
-0
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
...test/cases/adapters/postgresql/postgresql_adapter_test.rb
+7
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
f4f496df
*
When connecting to a non-existant postgresql database, the error:
`ActiveRecord::NoDatabaseError`
will now be raised. When being used with Rails
the error message will include information on how to create a database:
`rake db:create`
*Richard Schneeman*
*
Do not raise
`'can not touch on a new record object'`
exception on destroying already destroyed
`belongs_to`
association with
`touch: true`
option
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
f4f496df
...
...
@@ -865,6 +865,12 @@ def connect
PostgreSQLColumn
.
money_precision
=
(
postgresql_version
>=
80300
)
?
19
:
10
configure_connection
rescue
::
PG
::
Error
=>
error
if
error
.
message
.
include?
(
"does not exist"
)
raise
ActiveRecord
::
NoDatabaseError
.
new
(
error
.
message
)
else
raise
error
end
end
# Configures the encoding, verbosity, schema search path, and time zone of the connection.
...
...
activerecord/lib/active_record/errors.rb
浏览文件 @
f4f496df
...
...
@@ -94,6 +94,18 @@ class InvalidForeignKey < WrappedDatabaseException
class
PreparedStatementInvalid
<
ActiveRecordError
end
# Raised when a given database does not exist
class
NoDatabaseError
<
ActiveRecordError
def
initialize
(
message
)
super
extend_message
(
message
)
end
# can be over written to add additional error information.
def
extend_message
(
message
)
message
end
end
# Raised on attempt to save stale record. Record is stale when it's being saved in another query after
# instantiation, for example, when two users edit the same wiki page and one starts editing and saves
# the page before the other.
...
...
activerecord/lib/active_record/railtie.rb
浏览文件 @
f4f496df
...
...
@@ -122,6 +122,14 @@ class Railtie < Rails::Railtie # :nodoc:
# and then establishes the connection.
initializer
"active_record.initialize_database"
do
|
app
|
ActiveSupport
.
on_load
(
:active_record
)
do
class
ActiveRecord::NoDatabaseError
def
extend_message
(
message
)
message
<<
"Run `$ bin/rake db:create db:migrate` to create your database"
message
end
end
self
.
configurations
=
app
.
config
.
database_configuration
||
{}
establish_connection
end
...
...
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
浏览文件 @
f4f496df
...
...
@@ -10,6 +10,13 @@ def setup
@connection
.
exec_query
(
'create table ex(id serial primary key, number integer, data character varying(255))'
)
end
def
test_bad_connection
assert_raise
ActiveRecord
::
NoDatabaseError
do
connection
=
ActiveRecord
::
Base
.
postgresql_connection
(
database:
"should_not_exist-cinco-dog-db"
,
adapter:
"postgresql"
)
connection
.
exec_query
(
'drop table if exists ex'
)
end
end
def
test_valid_column
column
=
@connection
.
columns
(
'ex'
).
find
{
|
col
|
col
.
name
==
'id'
}
assert
@connection
.
valid_type?
(
column
.
type
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录