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

Ticket #11301: fixed_rake_db_create_drop_tasks.2.diff

File fixed_rake_db_create_drop_tasks.2.diff, 1.6 kB (added by matt, 7 months ago)

(same as previous patch but with better error handling when the connection can't be dropped)

  • railties/lib/tasks/databases.rake

    old new  
    3737        @collation = ENV['COLLATION'] || 'utf8_general_ci' 
    3838        begin 
    3939          ActiveRecord::Base.establish_connection(config.merge({'database' => nil})) 
    40           ActiveRecord::Base.connection.create_database(config['database'], {:charset => @charset, :collation => @collation}) 
     40          ActiveRecord::Base.connection.create_database(config['database'], {:charset => (config['database']['charset'] || @charset), :collation => (config['database']['charset'] || @collation)}) 
    4141          ActiveRecord::Base.establish_connection(config) 
    4242        rescue 
    43           $stderr.puts "Couldn't create database for #{config.inspect}
     43          $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{@charset}, collation: #{@collation} (if you set the charset manually, make sure you have a matching collation)
    4444        end 
    4545      when 'postgresql' 
    4646        `createdb "#{config['database']}" -E utf8` 
     
    6868 
    6969  desc 'Drops the database for the current RAILS_ENV' 
    7070  task :drop => :environment do 
    71     drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development']) 
     71    config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] 
     72    begin 
     73      drop_database(config) 
     74    rescue Exception => e 
     75      puts "#{e.inspect} - #{config['database']} might have been already dropped" 
     76    end 
    7277  end 
    7378 
    7479  def local_database?(config, &block)