Skip to content

Commit

Permalink
PostgreSQL: Connect to template1 database when creating or dropping db
Browse files Browse the repository at this point in the history
 * The template1 database is always available on a PostgreSQL install
 * The previous behavior expected a database with the same name as the
   connecting user, which may not be available

Signed-off-by: Michael Koziarski <michael@koziarski.com>

[#38 state:resolved]
  • Loading branch information
Pete Deffendol authored and NZKoz committed May 4, 2008
1 parent 96980bd commit 205750c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions railties/lib/tasks/databases.rake
Expand Up @@ -45,7 +45,7 @@ namespace :db do
when 'postgresql'
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
begin
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding)
ActiveRecord::Base.establish_connection(config)
rescue
Expand Down Expand Up @@ -373,7 +373,7 @@ def drop_database(config)
when /^sqlite/
FileUtils.rm(File.join(RAILS_ROOT, config['database']))
when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
ActiveRecord::Base.connection.drop_database config['database']
end
end
Expand Down

0 comments on commit 205750c

Please sign in to comment.