# A complex active record question

**URL:** <https://www.ruby-forum.com/t/a-complex-active-record-question/69785>\
**Category:** Rails\
**Created:** [September 24, 2006, 3:58am UTC](https://www.ruby-forum.com/t/a-complex-active-record-question/69785 "2006-09-24T03:58:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wijnand\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a9adbd/32.png) [@Wijnand\_W](https://www.ruby-forum.com/u/Wijnand_W)\
**Post date:** [September 24, 2006, 3:58am UTC](https://www.ruby-forum.com/t/a-complex-active-record-question/69785/1 "2006-09-24T03:58:36Z")

</div>

Hi all,

I am developing a web frontend for a monitoring system with a legacy  
database schema which we cannot change now. This monitoring system has  
a table for every kind of probe it knows. Those probes are defined in  
a database table too, the table is named probe.  
Table creation (mysql format) is displayed at:  
[http://nedbsd.nl/~wijnand/probes.sql](http://nedbsd.nl/~wijnand/probes.sql)

Some probes are added by hand and some are not. So some probes will  
need creation forms. All probes performed by the monitoring server are  
created by hand. This is one example of its entry in the probe table:  
INSERT into pr\_tcpconnect\_def set id = ‘1’, description = ‘empty’;  
INSERT into probe set id = ‘14’, name = ‘tcpconnect’, description =  
‘Connect to a TCP port’, addbyhand = ‘yes’, class = ‘’, graphgroup =  
‘ct’, graphtypes = ‘default’, comment = ‘’;

As you will see there is always a default record, don’t ask me why but  
I have to maintain that.

This tcpconnect probe has several tables with information. We have the  
table where the probe is created, in this case pr\_tcpconnect\_def as  
you can see at: [http://nedbsd.nl/~wijnand/pr\_tcpconnect\_def.sql](http://nedbsd.nl/~wijnand/pr_tcpconnect_def.sql)

This is one example, other remote probes have some different fields,  
but most are the same. So creating a entirely different model for each  
is not very DRY so I need to find a way to create a uniform way to  
create probes, whatever the type is.

All probes have results, the most current one is stored in the  
pr\_status table. The mysql definition is at:  
[http://nedbsd.nl/~wijnand/pr\_status.sql](http://nedbsd.nl/~wijnand/pr_status.sql)  
As you can see it refers to a server and a class. The class is for the  
probe type as found in the probe table and the probe definition is in  
pr\_probename\_def.

Most probes have a table with raw results. Lets show the raw results  
of tcpconnect: [http://nedbsd.nl/~wijnand/pr\_tcpconnect\_raw.sql](http://nedbsd.nl/~wijnand/pr_tcpconnect_raw.sql)

Most probes also have history tables for older results created from  
the \_raw table:  
[http://nedbsd.nl/~wijnand/pr\_tcpconnect\_day.sql](http://nedbsd.nl/~wijnand/pr_tcpconnect_day.sql) and  
[http://nedbsd.nl/~wijnand/pr\_tcpconnect\_week.sql](http://nedbsd.nl/~wijnand/pr_tcpconnect_week.sql)  
There are tables like this for day, week, month, year and 5year

I want to address it all in a uniform and DRY way. That should be  
possible using ruby because ruby is so dynamic. However, I am still a  
ruby and rails newbie and I don’t know yet where to start and what  
would be a good approach. I cannot change the schema, that is out of  
the question at this moment.

Does anyone have some good pointers on how to accomplish this, or is  
there anyone who already did a similar thing using rails? If so,  
please help me out. The application will be open sourced and I love to  
give full credits in the code for every helpfull suggestion.

Regards,  
Wijnand
