Hi, everyone!
I have a legacy database that we need to get data out of for a Rails
application. The data is ... not in the best shape. Originally, we
wrote the Rails application without any models that inherit from AR --
they''re just classes that do SQL queries to get the data (it''s
all
undocumented, the columns have names like svkrt, and it''s generally
incomprehensible, so we mostly copied queries out of a legacy
application). This is working, but it''s not ideal, for a lot of
reasons.
Since we only need to read from the legacy database (no need to update
it), and since someone else is working on a PHP application to access
the same data and is tearing their hair out at the legacy schema, the
client gave us permission to go ahead and write a program to create a
friendly, understood schema from the old one. Great!
I thought this would be relatively simple. I''d use my existing (non-AR
derived) models to read the data, which I know works. Then I''d create
new AR models to write the data to the new database. I thought if I
included all the old models and then included all the new models, things
would be easy ... unfortunately, that''s not the case. The old models
are
brought in just fine. However, the new models define relationships using
AR methods, like "belongs_to" or "has_and_belongs_to_many".
The first
class that''s loaded gives me an error like this:
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.2.2825/lib/active_support/core_ext/hash/keys.rb:48:in
`assert_valid_keys'': Unknown key(s): class (ArgumentError)
Does anyone have suggestions on how I can load the model classes and
have them figure out what they need to require, a la Rails? But outside
of Rails, of course, since this is a job that will run regularly via
cron every hour or so.
On IRC, people suggested I look at const_missing?, particularly how
it''s
used in dependencies.rb. It wa also suggested that dependencies.rb is a
very complicated file and this could take a while to figure out. So ...
I''ll look through dependencies.rb, but I''m hoping
there''s a simpler way
to use AR than trying to rewrite a portion of Rails for what I was
hoping was going to be a reasonably simple script.
If not, it might be simpler to just turn off all the relationships and
write stuff into the database that way, but it''s not my first choice.
Any help would be appreciated!
Thanks!
Jen