Permalink
Browse files

When running "rake db:drop" also drop test database in development en…

…vironment.
  • Loading branch information...
1 parent 64b0c88 commit 78de4fcd050b5f2f67a1bf974ba6960b4b017443 @dmitriy-kiriyenko dmitriy-kiriyenko committed Aug 4, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 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

0 comments on commit 78de4fc

Please sign in to comment.