Import old database into new schema in Rails

279 views Asked by At

I want to import my old database to new schema in rails. For that i have .rake file:

# /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

but after adding that file I can't even use any rake command. Here is some lines of trace:

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)>'
I am doing it by looking at this tutorial:

http://www.frick-web.at/blog/import-old-database-in-new-schema-with-mysql-and-rails

1

There are 1 answers

0
Aleks On BEST ANSWER

try

require Rails.root.join("lib/tasks/importer").to_s