database_tasks.rb 633 字节
Newer Older
P
Pat Allan 已提交
1
class ActiveRecord::Tasks::DatabaseTasks
2 3
  TASKS_PATTERNS = {
    /mysql/      => ActiveRecord::Tasks::MySQLDatabaseTasks,
4
    /postgresql/ => ActiveRecord::Tasks::PostgreSQLDatabaseTasks,
5 6
    /sqlite/     => ActiveRecord::Tasks::SQLiteDatabaseTasks
  }
P
Pat Allan 已提交
7

8 9
  def self.create(configuration)
    class_for_adapter(configuration['adapter']).new(configuration).create
P
Pat Allan 已提交
10 11 12 13
  rescue Exception => e
    $stderr.puts e, *(e.backtrace)
    $stderr.puts "Couldn't create database for #{configuration.inspect}"
  end
14 15 16 17 18

  def self.class_for_adapter(adapter)
    key = TASKS_PATTERNS.keys.detect { |key| adapter[key] }
    TASKS_PATTERNS[key]
  end
P
Pat Allan 已提交
19
end