Right now, our code is gradually getting cleaner and we do have hints of separation here and there, but we have decided we need to focus on developing our model appropriately. However, rather than try and refactor the awful database design, we want to build a clean object layer (the model) on top, have tests for it, and then drive everything through that layer so that later we are in a better position to fix the database. That leads to an interesting design problem.

One primary design goal is, as much as possible, only expose object responsibilities, not data. We're considering either using a ORM or the phrasebook pattern. Because our database is designed so poorly, while I do like ORMs, I'm thinking that perhaps a phrasebook would be a better way to go. That being said, ORMs can save a lot of agony, if done properly (and I find 'em quicker to implement.)

With an ORM, it should be easy to add custom, hand-written SQL for the numerous cases where our bad database design creates an obstacle for an ORM. Having used Class::DBI in the past, it seems like a good fit for this. Not having used DBIx::Class, I can't comment on it, but at least one of our programmers has said his experience with it suggests that there's a large performance hit on the initial loading of large schemas. Because this code is running as CGI and not mod_perl (and is in no shape to be converted), we can't afford that performance hit. I also hear great things about Rose::DB::Object, but I also haven't played with that yet.

So given the desire to create an model of a poorly designed database and the need to add custom SQL in various bits of it (and in some places, even post-processing with Perl to get reasonable data), what approach would you take? ORM (which one), phrasebook, or something else altogether? I realize much of this is vague and I'll be researching myself, but suggestions welcome.

The database is MySQL 4.1.19.

Cheers,
Ovid

New address of my CGI Course.


In reply to Creating a model of a bad database by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.