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

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

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?


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

Simple custom painting mistake

java swing awt double-buffering

I just started coding again and I guess I forgot how to double buffer. This is the code I have now and I'm not sure what I am missing. When I start it there is just a white screen, no oval.

jQuery image upload & crop by cakephp


In my project, image need to upload and crop. So, I have taken help from

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.