mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user