4

I have a static table entry that's shared by several databases/website. By static, I mean the data is read but never updated by the websites. Currently, all websites are served from the same server but that may change.

I want to minimize the need for creating/maintaining this table for each of the websites, so I thought about turning it to a variable that's stored in a shared library that all websites have access to.

The problem is I use an ORM and use foreign key constraints to ensure referential integrity of the ids used from that static table, so by removing that table out of the MySQL database into a variable, how can I still get referential integrity for the ids referenced from that table? Do I have to do it entirely programmatically or is there a trick to still treat the data as if coming from a real db table.

My database definition (using Propel) originally looked like this, where the refer table had a field linkto that was referencing the id of the entry table. Now that the entry table is in code, I can't do the foreign-key trick any more, or can I somehow get the same effect?

  <table name="entry">
    <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
    <column name="title" type="VARCHAR" size="500" required="true" />
  </table>

  <table name="refer">
    <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
    <column name="linkto" type="INTEGER"/>
     <foreign-key foreignTable="entry">
        <reference local="linkto" foreign="id" />
    </foreign-key>
  </table>

And of course are these any other efficient ways to do the same thing? I just don't want to have to repeat that table for several websites.

sami
  • 7,515
  • 8
  • 33
  • 37

1 Answers1

1

You could create a constraint -- a mighty verbose one, probably, if your id FK is being replaced by a link -- but then you'd still be in the position of maintaining this constraint for each web site. It would help to know what these tables are actually tracking/being used for if you want suggestions for other ways of handling it.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • looks like SO was not displaying my table definition even though I had in the post. I've highlighted it as code so now it's showing. Hope this clarifies things a bit. – sami Dec 27 '10 at 14:12
  • @sami - it would still help to know what it is used for. – tvanfosson Dec 27 '10 at 14:46