EAV model - rule implementation

From: Jayadevan M <jayadevan(dot)maymala(at)ibsplc(dot)com>
To: "'pgeu-general(at)postgresql(dot)org'" <pgeu-general(at)postgresql(dot)org>
Subject: EAV model - rule implementation
Date: 2013-06-06 09:57:40
Message-ID: 3411BBAFF5A2244FA405CC91D9473A6023695DA2@PBOX2.ibsplc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgeu-general

Hello all,

I have a database designed using Entity Attrubite Value model (OK, bad decision. But....). I have the following key tables
1) One for all possible entity types (Car, Refrigerator etc)
2) One for entities (each one will be of some 'type' - )
3) One for all possible attributes ("Make", "Model", "Year of Manufacture")
4) One for the EAV data

Now, I have a couple of tables to capture rules for the attributes. This will link "entity type", attribute and rules.
Rules may be of the following types -
So Attribute X of Entity type D has to be Unique and/or Non-NULL, and/or has to be one of a set of values. There is a child table also, to capture the domain values situation (example - timezone attribute should hold only values PST,EST...).

Which is the best way to enforce these rules? I was thinking about statement level trigger in the EAV table. It has to be statement level because only after all the attributes for an entity has gone in can alidation happen. But statement level triggers, it seems, can't see NEW values. So is using the Rule system the right approach?

The EAV approach is used because there won't be any complex business rule processing, the number of entities will be limited to a million or so etc. (So EAV tables has a million* avg number of attributes per entity)

Thoughts/Suggestions?

Jayadevan M
Senior Technical Architect - TCC
IBS Software Services Private Limited
5th Floor/NILA, Technopark Campus, Trivandrum 695 581, Kerala, India
Phone: +91- 471-6614352 Mobile: +91 94952 00950
Email: Jayadevan(dot)Maymala(at)ibsplc(dot)com www.ibsplc.com<http://www.ibsplc.com/>

DISCLAIMER: "The information in this e-mail and any attachment is intended only for the person to whom it is addressed and may contain confidential and/or privileged material. If you have received this e-mail in error, kindly contact the sender and destroy all copies of the original communication. IBS makes no warranty, express or implied, nor guarantees the accuracy, adequacy or completeness of the information contained in this email or any attachment and is not liable for any errors, defects, omissions, viruses or for resultant loss or damage, if any, direct or indirect."

Browse pgeu-general by date

  From Date Subject
Next Message Jiří Pavlovský 2013-06-25 15:38:53 utf8 errors
Previous Message Stefan Kaltenbrunner 2013-05-25 12:55:22 Re: restrictions on pg_cancel_backend