Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7489

Show
Ignore:
Timestamp:
09/15/07 22:56:07 (1 year ago)
Author:
david
Message:

Added db:drop:all to drop all databases declared in config/database.yml [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r7422 r7489  
    11*SVN* 
     2 
     3* Added db:drop:all to drop all databases declared in config/database.yml [DHH] 
    24 
    35* Use attribute pairs instead of the migration name to create add and remove column migrations.  Closes #9166 [lifofifo] 
  • trunk/railties/lib/tasks/databases.rake

    r7398 r7489  
    2929            ActiveRecord::Base.connection.create_database(config['database'], {:charset => @charset, :collation => @collation}) 
    3030            ActiveRecord::Base.establish_connection(config) 
    31             p "MySQL #{config['database']} database succesfully created" 
    3231          rescue 
    3332            $stderr.puts "Couldn't create database for #{config.inspect}" 
     
    4847  end 
    4948 
    50   desc 'Drops the database for the current environment' 
     49  namespace :drop do 
     50    desc 'Drops all the local databases defined in config/database.yml' 
     51    task :all => :environment do 
     52      ActiveRecord::Base.configurations.each_value do |config| 
     53        drop_database(config) 
     54      end 
     55    end 
     56  end 
     57 
     58  desc 'Drops the database for the current RAILS_ENV' 
    5159  task :drop => :environment do 
    52     config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] 
    53     case config['adapter'] 
    54     when 'mysql' 
    55       ActiveRecord::Base.connection.drop_database config['database'] 
    56     when /^sqlite/ 
    57       FileUtils.rm_f File.join(RAILS_ROOT, config['database']) 
    58     when 'postgresql' 
    59       `dropdb "#{config['database']}"` 
    60     end 
     60    drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development']) 
    6161  end 
    6262 
     
    267267end 
    268268 
     269def drop_database(config) 
     270  case config['adapter'] 
     271  when 'mysql' 
     272    ActiveRecord::Base.connection.drop_database config['database'] 
     273  when /^sqlite/ 
     274    FileUtils.rm_f(File.join(RAILS_ROOT, config['database'])) 
     275  when 'postgresql' 
     276    `dropdb "#{config['database']}"` 
     277  end 
     278end 
     279 
    269280def session_table_name 
    270281  ActiveRecord::Base.pluralize_table_names ? :sessions : :session