Use 'postgres' database instead of 'template1'

The 'postgres' database is meant for use by utilities and third
party applications. CONNECT permission to the 'template1' database
is usually only available to superusers which is why 'postgres'
should be preferred as users whith "CREATE DATABASE" permissions
are not neccessarily superusers.
This commit is contained in:
Tarmo Tänav
2008-05-13 17:26:05 +03:00
committed by Pratik Naik
parent 9fb01ce4b1
commit 4dedc7ddca

View File

@@ -45,7 +45,7 @@ namespace :db do
when 'postgresql'
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
begin
ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres'))
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
ActiveRecord::Base.establish_connection(config)
rescue
@@ -368,7 +368,7 @@ def drop_database(config)
when /^sqlite/
FileUtils.rm(File.join(RAILS_ROOT, config['database']))
when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres'))
ActiveRecord::Base.connection.drop_database config['database']
end
end