Ticket #9045: rails_create_drop_db_postgres_9180.patch
| File rails_create_drop_db_postgres_9180.patch, 1.7 kB (added by nicksieger, 9 months ago) |
|---|
-
a/railties/lib/tasks/databases.rake
old new 43 43 $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation} (if you set the charset manually, make sure you have a matching collation)" 44 44 end 45 45 when 'postgresql' 46 `createdb "#{config['database']}" -E utf8` 46 @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' 47 begin 48 ActiveRecord::Base.establish_connection(config.merge({'database' => nil})) 49 ActiveRecord::Base.connection.create_database(config['database'], {:encoding => @encoding}) 50 ActiveRecord::Base.establish_connection(config) 51 rescue 52 $stderr.puts $!, *($!.backtrace) 53 $stderr.puts "Couldn't create database for #{config.inspect}" 54 end 47 55 when 'sqlite' 48 56 `sqlite "#{config['database']}"` 49 57 when 'sqlite3' 50 58 `sqlite3 "#{config['database']}"` 51 59 end 52 60 else 53 p"#{config['database']} already exists"61 $stderr.puts "#{config['database']} already exists" 54 62 end 55 63 end 56 64 … … 365 373 when /^sqlite/ 366 374 FileUtils.rm(File.join(RAILS_ROOT, config['database'])) 367 375 when 'postgresql' 368 ActiveRecord::Base. clear_active_connections!369 `dropdb "#{config['database']}"`376 ActiveRecord::Base.establish_connection(config.merge({'database' => nil})) 377 ActiveRecord::Base.connection.drop_database config['database'] 370 378 end 371 379 end 372 380