提交 f73b8456 编写于 作者: A Akira Matsuda

Defer loading each DB Tasks class from AR DatabaseTasks

Because we don't need to load tasks for DBs that we don't use for the current app.
Also, these Tasks classes load AR::Base in their class level, and so immediately kick :active_record on_load hooks.
This used to happen when we were loading tasks, not when we run a task.
上级 22bfc5f4
......@@ -71,9 +71,9 @@ def register_task(pattern, task)
@tasks[pattern] = task
end
register_task(/mysql/, ActiveRecord::Tasks::MySQLDatabaseTasks)
register_task(/postgresql/, ActiveRecord::Tasks::PostgreSQLDatabaseTasks)
register_task(/sqlite/, ActiveRecord::Tasks::SQLiteDatabaseTasks)
register_task(/mysql/, 'ActiveRecord::Tasks::MySQLDatabaseTasks')
register_task(/postgresql/, 'ActiveRecord::Tasks::PostgreSQLDatabaseTasks')
register_task(/sqlite/, 'ActiveRecord::Tasks::SQLiteDatabaseTasks')
def db_dir
@db_dir ||= Rails.application.config.paths["db"].first
......@@ -288,11 +288,11 @@ def dump_schema_cache(conn, filename)
private
def class_for_adapter(adapter)
key = @tasks.keys.detect { |pattern| adapter[pattern] }
unless key
_key, task = @tasks.each_pair.detect { |pattern, _task| adapter[pattern] }
unless task
raise DatabaseNotSupported, "Rake tasks not supported by '#{adapter}' adapter"
end
@tasks[key]
task.is_a?(String) ? task.constantize : task
end
def each_current_configuration(environment)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册