Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2419 from dmitriy-kiriyenko/drop_test_database_in…

…_development_when_running_rake_db_drop

When running "rake db:drop" also drop test database in development environment
  • Loading branch information...
commit b064614ffbb074807cb69b6ea785a5f01643682c 2 parents 0e8a4b3 + 78de4fc
@fxn fxn authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 activerecord/lib/active_record/railties/databases.rake
View
26 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
Please sign in to comment.
Something went wrong with that request. Please try again.