diff options
Diffstat (limited to 'activerecord/lib/active_record/tasks/database_tasks.rb')
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index a72ec0175b..d0d3ea12dd 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -1,14 +1,19 @@ class ActiveRecord::Tasks::DatabaseTasks - def self.create(configuration) - if File.exist?(configuration['database']) - $stderr.puts "#{configuration['database']} already exists" - return - end + TASKS_PATTERNS = { + /mysql/ => ActiveRecord::Tasks::MySQLDatabaseTasks, + # /postgresql/ => ActiveRecord::Tasks::PostgreSQLTasker, + /sqlite/ => ActiveRecord::Tasks::SQLiteDatabaseTasks + } - ActiveRecord::Base.establish_connection(configuration) - ActiveRecord::Base.connection + def self.create(configuration) + class_for_adapter(configuration['adapter']).new(configuration).create rescue Exception => e $stderr.puts e, *(e.backtrace) $stderr.puts "Couldn't create database for #{configuration.inspect}" end + + def self.class_for_adapter(adapter) + key = TASKS_PATTERNS.keys.detect { |key| adapter[key] } + TASKS_PATTERNS[key] + end end |