mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
PostgreSQL: use create_ and drop_database for rake tasks. Closes #9045 [ez, nicksieger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9183 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
e4e3df8ef8
commit
25eeea7197
1 changed files with 26 additions and 18 deletions
|
@ -36,21 +36,29 @@ namespace :db do
|
|||
@charset = ENV['CHARSET'] || 'utf8'
|
||||
@collation = ENV['COLLATION'] || 'utf8_general_ci'
|
||||
begin
|
||||
ActiveRecord::Base.establish_connection(config.merge({'database' => nil}))
|
||||
ActiveRecord::Base.connection.create_database(config['database'], {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)})
|
||||
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
||||
ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation))
|
||||
ActiveRecord::Base.establish_connection(config)
|
||||
rescue
|
||||
$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)"
|
||||
end
|
||||
when 'postgresql'
|
||||
`createdb "#{config['database']}" -E utf8`
|
||||
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
|
||||
begin
|
||||
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
||||
ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding)
|
||||
ActiveRecord::Base.establish_connection(config)
|
||||
rescue
|
||||
$stderr.puts $!, *($!.backtrace)
|
||||
$stderr.puts "Couldn't create database for #{config.inspect}"
|
||||
end
|
||||
when 'sqlite'
|
||||
`sqlite "#{config['database']}"`
|
||||
when 'sqlite3'
|
||||
`sqlite3 "#{config['database']}"`
|
||||
end
|
||||
else
|
||||
p "#{config['database']} already exists"
|
||||
$stderr.puts "#{config['database']} already exists"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -365,8 +373,8 @@ def drop_database(config)
|
|||
when /^sqlite/
|
||||
FileUtils.rm(File.join(RAILS_ROOT, config['database']))
|
||||
when 'postgresql'
|
||||
ActiveRecord::Base.clear_active_connections!
|
||||
`dropdb "#{config['database']}"`
|
||||
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
||||
ActiveRecord::Base.connection.drop_database config['database']
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue