diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-15 22:56:07 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-15 22:56:07 +0000 |
commit | 694f15758c5af88f6d288d72650e2fcd2cfccfe7 (patch) | |
tree | 054c42bb35f4d335831f59cdef80c9411c8754fa /railties/lib/tasks | |
parent | 148202d401c7114c8ceb69f4f9effaba38461124 (diff) | |
download | rails-694f15758c5af88f6d288d72650e2fcd2cfccfe7.tar.gz rails-694f15758c5af88f6d288d72650e2fcd2cfccfe7.tar.bz2 rails-694f15758c5af88f6d288d72650e2fcd2cfccfe7.zip |
Added db:drop:all to drop all databases declared in config/database.yml [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7489 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/tasks')
-rw-r--r-- | railties/lib/tasks/databases.rake | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index a761689932..ef2c25663a 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -28,7 +28,6 @@ namespace :db do ActiveRecord::Base.establish_connection(config.merge({'database' => nil})) ActiveRecord::Base.connection.create_database(config['database'], {:charset => @charset, :collation => @collation}) ActiveRecord::Base.establish_connection(config) - p "MySQL #{config['database']} database succesfully created" rescue $stderr.puts "Couldn't create database for #{config.inspect}" end @@ -47,19 +46,20 @@ namespace :db do end end - desc 'Drops the database for the current environment' - task :drop => :environment do - config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] - case config['adapter'] - when 'mysql' - ActiveRecord::Base.connection.drop_database config['database'] - when /^sqlite/ - FileUtils.rm_f File.join(RAILS_ROOT, config['database']) - when 'postgresql' - `dropdb "#{config['database']}"` + namespace :drop do + desc 'Drops all the local databases defined in config/database.yml' + task :all => :environment do + ActiveRecord::Base.configurations.each_value do |config| + drop_database(config) + end end end + desc 'Drops the database for the current RAILS_ENV' + task :drop => :environment do + drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development']) + end + desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" task :migrate => :environment do ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) @@ -266,6 +266,17 @@ namespace :db do end end +def drop_database(config) + case config['adapter'] + when 'mysql' + ActiveRecord::Base.connection.drop_database config['database'] + when /^sqlite/ + FileUtils.rm_f(File.join(RAILS_ROOT, config['database'])) + when 'postgresql' + `dropdb "#{config['database']}"` + end +end + def session_table_name ActiveRecord::Base.pluralize_table_names ? :sessions : :session end |