Forum: Ruby on Rails Converting a Legacy Database Using ActiveRecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4bd51ab0f34f4337d0c293a9b3ddb9dc?d=identicon&s=25 Jake Schutz (Guest)
on 2007-01-22 23:45
I am in the process of writing some scripts to convert a legacy MySQL
database to something more rails friendly.  The Legacy database has a
blob field containing JPEG data which seems to be giving me some
problems (at least I think).  Here is the script that I have started:


require 'rubygems'
require 'active_record'

class OldStaff < ActiveRecord::Base
  def self.table_name
    "staff"
  end
end

OldStaff.establish_connection(
#ActiveRecord::Base.establish_connection(
  :adapter  => "mysql",
  :host     => "localhost",
  :username => "username",
  :password => "password",
  :database => "legacy"
)

class StaffMember < ActiveRecord::Base
end

StaffMember.establish_connection(
  :adapter  => "mysql",
  :host     => "localhost",
  :username => "username",
  :password => "password",
  :database => "new_database"
)

ActiveRecord::Base.logger = Logger.new(STDOUT)

old_staff_members = OldStaff.find(:all)


If I try to run my script I get the following errors:

DEPRECATION WARNING: Reloadable::Subclasses has been deprecated and has
no effect.  See http://www.rubyonrails.org/deprecation for details.
(called from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:248)
DEPRECATION WARNING: Reloadable::Subclasses has been deprecated and has
no effect.  See http://www.rubyonrails.org/deprecation for details.
(called from
/usr/local/lib/ruby/site_ruby/1.8/active_record/observer.rb:106)
  OldStaff Load (0.094925)   SELECT * FROM staff
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:1246:in
`compute_type':
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:405:in
`to_constant_name': Anonymous modules have no name to be referenced by
(ArgumentError)
        from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:215:in
`qualified_name_for'
        from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:477:in
`const_missing'
        from (eval):1:in `compute_type'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:983:in
`instantiate_without_callbacks'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/callbacks.rb:215:in
`instantiate'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:390:in
`find_by_sql'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:390:in
`find_by_sql'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:924:in
`find_every'
        from
/usr/local/lib/ruby/site_ruby/1.8/active_record/base.rb:381:in `find'
        from convert_staff.rb:32

Ideally, after the find has been completed I'd like to create entries in
my new database based on the specific conversions.  The blob data will
be the same on the new database (unless I can find a better way to
handle this issue).

Any insight on this issue would be greatly appreciated.

Thanks,
Jake
This topic is locked and can not be replied to.