我正在尝试自定义db:structure:dump
和db:structure:load
任务,但出现以下错误:
$ rake db:structure:dump
rake aborted!
uninitialized constant Tasks::DatabaseTasks
我使用的代码只是从https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake复制的,删除了几行:
# lib/tasks/db.rake
require 'active_record'
Rake::Task['db:structure:dump'].clear
namespace :db do
namespace :structure do
desc 'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
task :dump => [:environment, :load_config] do
abcs = ActiveRecord::Base.configurations
filename = ENV['DB_STRUCTURE'] || File.join(Rails.root, "db", "structure.sql")
case abcs[Rails.env]['adapter']
when /mysql/, /postgresql/, /sqlite/
ActiveRecord::Tasks::DatabaseTasks.structure_dump(abcs[Rails.env], filename)
else
raise "Task not supported by '#{abcs[Rails.env]["adapter"]}'"
end
db_namespace['structure:dump'].reenable
end
end
end
我还应该要求或包括什么?