diff options
author | Dmitriy Kiriyenko <dmitriy.kiriyenko@gmail.com> | 2011-08-04 15:44:08 +0300 |
---|---|---|
committer | Dmitriy Kiriyenko <dmitriy.kiriyenko@anahoret.com> | 2011-09-29 15:07:09 +0300 |
commit | 78de4fcd050b5f2f67a1bf974ba6960b4b017443 (patch) | |
tree | 45949cb0026619ca49f29efb83f8bad64651f2c1 /activerecord | |
parent | 64b0c8888b908ede5372e0a70cb4cb8731d372ba (diff) | |
download | rails-78de4fcd050b5f2f67a1bf974ba6960b4b017443.tar.gz rails-78de4fcd050b5f2f67a1bf974ba6960b4b017443.tar.bz2 rails-78de4fcd050b5f2f67a1bf974ba6960b4b017443.zip |
When running "rake db:drop" also drop test database in development environment.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index b3316fd1a2..1009af850c 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -37,11 +37,7 @@ db_namespace = namespace :db do desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)' task :create => :load_config do - # Make the test database at the same time as the development one, if it exists - if Rails.env.development? && ActiveRecord::Base.configurations['test'] - create_database(ActiveRecord::Base.configurations['test']) - end - create_database(ActiveRecord::Base.configurations[Rails.env]) + configs_for_environment.each { |config| create_database(config) } end def mysql_creation_options(config) @@ -138,12 +134,7 @@ db_namespace = namespace :db do desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)' task :drop => :load_config do - config = ActiveRecord::Base.configurations[Rails.env || 'development'] - begin - drop_database(config) - rescue Exception => e - $stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}" - end + configs_for_environment.each { |config| drop_database_and_rescue(config) } end def local_database?(config, &block) @@ -548,6 +539,19 @@ def drop_database(config) end end +def drop_database_and_rescue(config) + begin + drop_database(config) + rescue Exception => e + $stderr.puts "Couldn't drop #{config['database']} : #{e.inspect}" + end +end + +def configs_for_environment + environments = [Rails.env, ("test" if Rails.env.development?)] + ActiveRecord::Base.configurations.values_at(*environments).compact +end + def session_table_name ActiveRecord::SessionStore::Session.table_name end |