提交 22b020db 编写于 作者: N Neeraj Singh 提交者: Jeremy Kemper

db:drop:all throws error when database does not exist [#2997 state:resolved]

Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 2de36463
......@@ -94,11 +94,7 @@ namespace :db do
desc 'Drops the database for the current RAILS_ENV'
task :drop => :load_config do
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
begin
drop_database(config)
rescue Exception => e
puts "Couldn't drop #{config['database']} : #{e.inspect}"
end
drop_database(config)
end
def local_database?(config, &block)
......@@ -410,15 +406,19 @@ namespace :db do
end
def drop_database(config)
case config['adapter']
when 'mysql'
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.drop_database config['database']
when /^sqlite/
FileUtils.rm(File.join(RAILS_ROOT, config['database']))
when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
ActiveRecord::Base.connection.drop_database config['database']
begin
case config['adapter']
when 'mysql'
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.drop_database config['database']
when /^sqlite/
FileUtils.rm(File.join(RAILS_ROOT, config['database']))
when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
ActiveRecord::Base.connection.drop_database config['database']
end
rescue Exception => e
puts "Couldn't drop #{config['database']} : #{e.inspect}"
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册