I’m working with a large DB that is also being used by another
application(s) so I really can’t change it. I’d like to wrap it in
ActiveRecord (or DataMapper/OG/Other ORM) models but it’s quite a
challenge because models (in db) have so many parameters that they have
been split across multiple tables. Views (on db) don’t come into
question since that would create huge joins and fetch far to much data
at once.
The DB structure probably has been generated by a program so it follows
some sort of logic, but I’m ok with the idea that I’m going to have to
map the thing once manually.
Another annoyance is the fact that the columns in the extra parameter
tables are prefixed with a short form of the table name, of course I’d
like to access them by the unprefixed name (there aren’t duplicate
names) since I don’t want to keep looking up the table number where
certain parameters are located (to use Ci.ipv6address instead of
Ci.xcit4_ipv6address)
Here’s an example model of ConfigurationItem in the DB (I’ve only picked
several tables and parameters for clarity):
CDM_CONFIGURATION_ITEMS
- CIT_OID
- CIT_CPU_OID
- CIT_NAME1
- CIT_NAME2
CDM_CONFIGURATION_ITEMS_X
- XCIT_CIT_OID
- XCIT_PURCHASEDATE
- XCIT_CINUMBER1
CDM_CONFIGURATION_ITEMS_X_SD_1
- XCIS1_CIT_OID
- XCIS1_CITEXT91
- XCIS1_IPADDRESS
CDM_CONFIGURATIO_ITEMS_X_SD_10 (n dropped from configuration when going
over 9)
- XCISA_CIT_OID (notice, after 9 comes A)
- XCISA_SHORTTEXT36
CDM_CONFIGURATIO_ITEMS_X_SD_18
- XCISI_CIT_OID
- XCISI_SERIALNUMBER
I’d like to do something like <%=
ConfigurationItem.find(:first).ipadress %> which would on demand make a
query that gets the value (or eager load all values) from
CDM_CONFIGURATION_ITEMS_X_SD_1.
Also it would be great to do something like @cis =
ConfigurationItem.find(:all, :include_fields => [:citext91, :name2])
that would magically create joins for the required tables.
I won’t do any writing through the DB connection, all of it is done via
a Java API which I have been using through JRuby successfully, but
that’s another story.
A colleague of mine already did this in lisp and of course I’d like to
show that ruby isn’t bad either.
Ideas? Discuss