aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railties
diff options
context:
space:
mode:
authorPat Allan <pat@freelancing-gods.com>2012-06-17 14:03:32 +0200
committerPat Allan <pat@freelancing-gods.com>2012-06-17 14:03:32 +0200
commite678d413bc14e9a38cd9818c7cf727339b2db9e7 (patch)
treebdf048cf453d84415366460eda59f939b8cbbf85 /activerecord/lib/active_record/railties
parentd29727235ae967e1ae4880ddfa5fd37d726f779d (diff)
downloadrails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.tar.gz
rails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.tar.bz2
rails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.zip
db:create for PostgreSQL pulled out into a class.
Diffstat (limited to 'activerecord/lib/active_record/railties')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake39
1 files changed, 7 insertions, 32 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 662c84bfda..3d9b1770ed 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -30,14 +30,18 @@ db_namespace = namespace :db do
# *defaults
next unless config['database']
# Only connect to local databases
- local_database?(config) { create_database(config) }
+ local_database?(config) {
+ ActiveRecord::Tasks::DatabaseTasks.create config
+ }
end
end
end
desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
task :create => :load_config do
- configs_for_environment.each { |config| create_database(config) }
+ configs_for_environment.each { |config|
+ ActiveRecord::Tasks::DatabaseTasks.create config
+ }
ActiveRecord::Base.establish_connection(configs_for_environment.first)
end
@@ -47,35 +51,6 @@ db_namespace = namespace :db do
{:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
end
- def create_database(config)
- begin
- if config['adapter'] =~ /sqlite/
- ActiveRecord::Tasks::DatabaseTasks.create config
- return # Skip the else clause of begin/rescue
- else
- ActiveRecord::Base.establish_connection(config)
- ActiveRecord::Base.connection
- end
- rescue
- case config['adapter']
- when /mysql/
- ActiveRecord::Tasks::DatabaseTasks.create config
- when /postgresql/
- @encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
- begin
- ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
- ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
- ActiveRecord::Base.establish_connection(config)
- rescue Exception => e
- $stderr.puts e, *(e.backtrace)
- $stderr.puts "Couldn't create database for #{config.inspect}"
- end
- end
- else
- $stderr.puts "#{config['database']} already exists"
- end
- end
-
namespace :drop do
# desc 'Drops all the local databases defined in config/database.yml'
task :all => :load_config do
@@ -475,7 +450,7 @@ db_namespace = namespace :db do
when /postgresql/
ActiveRecord::Base.clear_active_connections!
drop_database(abcs['test'])
- create_database(abcs['test'])
+ ActiveRecord::Tasks::DatabaseTasks.create abcs['test']
when /sqlite/
dbfile = abcs['test']['database']
File.delete(dbfile) if File.exist?(dbfile)