diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-12-23 07:28:40 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-12-23 07:28:40 -0800 |
commit | f4f496dfeb8ff1a9e78d12d943235c0a630ff55c (patch) | |
tree | e1993de87e010ba4c917c605d8b85fc0fe6bad5a /activerecord/lib | |
parent | b4d7be95e635da64b99e833a93c345bb4d6f2ba2 (diff) | |
parent | 0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763 (diff) | |
download | rails-f4f496dfeb8ff1a9e78d12d943235c0a630ff55c.tar.gz rails-f4f496dfeb8ff1a9e78d12d943235c0a630ff55c.tar.bz2 rails-f4f496dfeb8ff1a9e78d12d943235c0a630ff55c.zip |
Merge pull request #13427 from schneems/schneems/cannot-connect-postgres-error
Tell how to Create a Database in Error Message
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 8 |
3 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index dd3bfa5546..95cd69d5ad 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -865,6 +865,12 @@ module ActiveRecord 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. diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 2602f79db9..7f6228131f 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -94,6 +94,18 @@ module ActiveRecord 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. diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index eef08aea88..ff98c829f4 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -122,6 +122,14 @@ module ActiveRecord # 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 |