i attempting migrate legacy data ms sql database rails application. have added configuration in freetds connecting properly. in gemfile, have added tiny_tds , activerecord-sqlserver-adapter, respectively.
i have created file house classes legacy database translate activerecord:
class legacyuser < activerecord::base establish_connection :legacy set_table_name 'users' end . . .
database.yml
legacy: adapter: sqlserver mode: odbc dsn: legacy_db_name host: db_host_name database: legacy_db_name port: 1433 username: username password: password
then have rake tasks convert data:
legacy.rake
desc 'migrate users' task :users => :environment require 'lib/tasks/legacy_classes' legacyuser.each |user| begin new_user = user.new new_user.attributes = { :firstname => user.firstname, :lastname => user.lastname, :email => user.email, :created_at => time.now, :updated_at => time.now } new_user.save! puts "user #{user.id} migrated" rescue puts "error migrating #{user.id}" end end
at point trying rake task 'connect' legacy database.
when try 'rake users', get:
rake aborted! database configuration not specify adapter
it looks me have specified adapter. proper way configure this?
also side question, in 'classes' file legacy database tables, should of tables mirror 'new' rails database schema? ideally want able connect various tables in legacy database , fit them new database schema needed. associations in old not match new, nor naming conventions.
any appreciated. thanks.
update
still experiencing error. sadly, threads find have had same error odd spacing issues in database.yml file. took time go through , make sure of spacing matched other configurations. given vague error not sure check past instructions setting activerecord-sqlserver-adapter.
got answer here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/250
'you can try connecting db so, works on branch on rails 4:'
class legacytable < activerecord::base establish_connection({ :adapter => "sqlserver", :host => "host", :username => "user", :password => "pass", :database => "dbname" })
this solved issue. hope helps in future.
Comments
Post a Comment