I am trying to transfer stale data from an MS SQL database to my Rails application. I added a configuration to freetds that connects correctly. In my Gemfile, I added tiny_tds and activerecord-sqlserver-adapter , respectively.
I created a file for placing classes from the old database for translation to 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 I have rake tasks to convert the data:
legacy.rake
desc 'migrate users' task :users => :environment do require 'lib/tasks/legacy_classes' LegacyUser.each do |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} successfully migrated" rescue puts "Error migrating #{user.id}" end end
At this point, I'm just trying to get the rake task to "connect" to the old database.
When I try to use "rake users", I get:
rake aborted! database configuration does not specify adapter
It seems to me that I clearly indicated the adapter. What is the correct way to configure it?
Also, as a side question, in my βclassesβ file for legacy database tables, should all of these tables display a βnewβ Rails database schema? Ideally, I want to be able to simply connect to various tables in the old database and insert them into the new database schema where necessary. Associations in the old do not correspond to the new, as well as naming conventions.
Any help is appreciated. Thanks.
Update
This error still occurs. Unfortunately, the only threads I could find that had the same error were odd-interval problems in the database.yml file. So I really took the time to go through and make sure that all the intervals match my other configurations. Given that this is a foggy mistake, Iβm not even sure what to check past instructions for setting up the activerecord-sqlserver adapter.