将旧数据库导入 Rails 中的新模式
Import old database into new schema in Rails
我想将旧数据库导入 rails 中的新模式。
为此,我有 .rake 文件:
# /lib/tasks/project_name.rake:
namespace :project_name do
require Rails.root + "lib/tasks/importer"
desc "Import old database, usage: rake project_name:import['old_database_name']"
task :import, :oldDatabase, needs::environment do |t, args|
args.with_defaults(oldDatabase: "import")
oldDatabaseName = args.oldDatabse
newDatabaseName = YAML::load(IO.read(Rails.root.join("config/database.yml")))[Rails.env]["database"]
importer = Importer.new newDatabaseName, oldDatabaseName
importer.execute
end
end
但是在添加该文件后我什至无法使用任何 rake 命令。
这是一些跟踪行:
no implicit conversion of pathname into string
/Users/user/Desktop/rails/dis/lib/tasks/project_name.rake:2:in `block in <top (required)>'
/Users/user/Desktop/rails/dis/lib/tasks/project_name.rake:1:in `<top (required)>'
我正在通过查看本教程来做到这一点:
http://www.frick-web.at/blog/import-old-database-in-new-schema-with-mysql-and-rails
尝试
require Rails.root.join("lib/tasks/importer").to_s
我想将旧数据库导入 rails 中的新模式。 为此,我有 .rake 文件:
# /lib/tasks/project_name.rake:
namespace :project_name do
require Rails.root + "lib/tasks/importer"
desc "Import old database, usage: rake project_name:import['old_database_name']"
task :import, :oldDatabase, needs::environment do |t, args|
args.with_defaults(oldDatabase: "import")
oldDatabaseName = args.oldDatabse
newDatabaseName = YAML::load(IO.read(Rails.root.join("config/database.yml")))[Rails.env]["database"]
importer = Importer.new newDatabaseName, oldDatabaseName
importer.execute
end
end
但是在添加该文件后我什至无法使用任何 rake 命令。 这是一些跟踪行:
no implicit conversion of pathname into string
/Users/user/Desktop/rails/dis/lib/tasks/project_name.rake:2:in `block in <top (required)>'
/Users/user/Desktop/rails/dis/lib/tasks/project_name.rake:1:in `<top (required)>'
http://www.frick-web.at/blog/import-old-database-in-new-schema-with-mysql-and-rails
尝试
require Rails.root.join("lib/tasks/importer").to_s