diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/databases.rake | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 14 |
3 files changed, 21 insertions, 12 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index f8526bb691..c6dc7db2e8 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -137,6 +137,12 @@ module ActiveRecord end end + module Tasks + extend ActiveSupport::Autoload + + autoload :DatabaseTasks + end + autoload :TestCase autoload :TestFixtures, 'active_record/fixtures' end diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index d8d4834d22..b44d479fb6 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -50,18 +50,7 @@ db_namespace = namespace :db do def create_database(config) begin if config['adapter'] =~ /sqlite/ - if File.exist?(config['database']) - $stderr.puts "#{config['database']} already exists" - else - begin - # Create the SQLite database - ActiveRecord::Base.establish_connection(config) - ActiveRecord::Base.connection - rescue Exception => e - $stderr.puts e, *(e.backtrace) - $stderr.puts "Couldn't create database for #{config.inspect}" - end - end + ActiveRecord::Tasks::DatabaseTasks.create config return # Skip the else clause of begin/rescue else ActiveRecord::Base.establish_connection(config) diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb new file mode 100644 index 0000000000..a72ec0175b --- /dev/null +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -0,0 +1,14 @@ +class ActiveRecord::Tasks::DatabaseTasks + def self.create(configuration) + if File.exist?(configuration['database']) + $stderr.puts "#{configuration['database']} already exists" + return + end + + ActiveRecord::Base.establish_connection(configuration) + ActiveRecord::Base.connection + rescue Exception => e + $stderr.puts e, *(e.backtrace) + $stderr.puts "Couldn't create database for #{configuration.inspect}" + end +end |