diff options
author | Jeremy Kemper <jeremykemper@gmail.com> | 2014-04-01 16:45:15 -0500 |
---|---|---|
committer | Jeremy Kemper <jeremykemper@gmail.com> | 2014-04-01 16:49:52 -0500 |
commit | 9aa7c25c28325f62815b6625bdfcc6dd7565165b (patch) | |
tree | 344e8c2b156e279ac2476f1222dbf40c33e04c55 /activerecord/lib/active_record/railtie.rb | |
parent | 5d0a4e0cb6134b86fc2795047aacb335c978e02e (diff) | |
download | rails-9aa7c25c28325f62815b6625bdfcc6dd7565165b.tar.gz rails-9aa7c25c28325f62815b6625bdfcc6dd7565165b.tar.bz2 rails-9aa7c25c28325f62815b6625bdfcc6dd7565165b.zip |
Clarify 'database does not exist' message and implementation.
* Clarify what the situation is and what to do.
* Advise loading schema using `rake db:setup` instead of migrating.
* Use a rescue in the initializer rather than extending the error
message in-place.
* Preserve the original backtrace of other errors by using `raise`
rather than raising again with `raise error`.
References 0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763
Diffstat (limited to 'activerecord/lib/active_record/railtie.rb')
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 11b564f8f9..a4ceacbf44 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -116,17 +116,22 @@ module ActiveRecord # and then establishes the connection. initializer "active_record.initialize_database" do |app| ActiveSupport.on_load(:active_record) do + self.configurations = Rails.application.config.database_configuration - class ActiveRecord::NoDatabaseError - remove_possible_method :extend_message - def extend_message(message) - message << "Run `$ bin/rake db:create db:migrate` to create your database" - message - end - end + begin + establish_connection + rescue ActiveRecord::NoDatabaseError + warn <<-end_warning +Oops - You have a database configured, but it doesn't exist yet! - self.configurations = Rails.application.config.database_configuration - establish_connection +Here's how to get started: + + 1. Configure your database in config/database.yml. + 2. Run `bin/rake db:create` to create the database. + 3. Run `bin/rake db:setup` to load your database schema. +end_warning + raise + end end end |