Connecting to an external MySQL server for legacy data on heroku using ActiveRecord

So I am building a new app that needs to do some importing of legacy data from an old app. The old apps database is mysql, which you obviously can't use on heroku, but I want to use postgres. Basically I am doing an ETL via activerecord.

Here's what I have so far:

# config/initializers/legacy_database.rb
LEGACY_DATABASE_URL = "mysql://myusername:#{ENV['LEGACY_DATABASE_PASSWORD']}@host/foo1008801154002"

# app/models/legacy.rb
class Legacy < ActiveRecord::Base
  establish_connection LEGACY_DATABASE_URL
end

# app/models/legacy/user.rb
class Legacy::User < Legacy
  self.table_name = 'users'
end

If I am in the console and I run Legacy::User.count I get back the correct count. However if I try to do something like Legacy::User.first I get the following error:

Legacy::User Load (54.0ms)  SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
Mysql::Error: Table 'foo1008801154002.legacies' doesn't exist: SHOW FULL FIELDS FROM `legacies`
ActiveRecord::StatementInvalid: Mysql::Error: Table 'foo1008801154002.legacies' doesn't exist: SHOW FULL FIELDS FROM `legacies`

I'm not sure why rails is adding on the .legacies to the table name, nor am I sure how to fix this. I figure it might be some setting in Legacy.connection

Any advice?

Answers


Well it was relatively simple. I had to add the line self.abstract_class = true to my Legacy Base class.


Just a note: if you have mysql2 gem in your bundle then need to put:

# config/initializers/legacy_database.rb
LEGACY_DATABASE_URL = "mysql2://myusername:#{ENV['LEGACY_DATABASE_PASSWORD']}@host/foo1008801154002"

(or load mysql gem in Gemfile)


Need Your Help

Bootstrap 3 form input element's size attribute does not change lenght of same

forms input size twitter-bootstrap-3

With Bootstrap 3, form input element size does not change as specified by size attribute, code snippet:

What do you use to test the handheld css on your website?

html css testing media handheld

I've been adding css support for handheld to my website but haven't been able to find a good tool for testing.