I'm really trying to do it right the first time ( or second since this is a re-design of a similar system ).
Once again, I'm working on a php/mysql web app for a tech support center which integrates web support, phone support, and an online knowledge base.
This question pertains to 2 tables which will be the heart of the design. Well the question is actually to make these 2 separate tables, or make it just one.
First I'll tell you about the current layout, .. then I'll talk about the newer layout that I thought of last night.
Layout 1
Currently it works a bit like the Thread/Post design of this forum, except i'm using Issues/Details.
Everytime there is a new issue, it adds a row to the Issue table with the topic information and customer id, .. however the details of the issue gets entered in the Details table related to the Issue table by the Issue ID.
The purpose of this is so that there can be multiple details relating to the same issue in the case that the problem was not solved in the first call.
This is what the schema looks like for these 2 tables now:
Code:
CREATE TABLE issues (
issue_id int(10) unsigned NOT NULL auto_increment,
contact_id int(10) unsigned default NULL,
group_id smallint(5) unsigned NOT NULL default '0',
topic varchar(100) default NULL,
presales varchar(20) default NULL,
PRIMARY KEY (issue_id)
)
CREATE TABLE details (
detail_id int(10) unsigned NOT NULL auto_increment,
issue_id int(10) unsigned NOT NULL default '0',
open datetime default NULL,
closed datetime default NULL,
agent_id int(10) unsigned NOT NULL default '0',
c_detail mediumtext,
a_detail mediumtext,
status varchar(10) NOT NULL default 'open',
PRIMARY KEY (detail_id)
)
Layout 2
Last night I was thinking of another Idea using only the Details table with a 'parent_id' field.
Every detail with a Parent ID of '0' would be the equivalent to the Issue. Then of course everything with a parent_id that is not 0 would just be a child.
Trade offs would be that I will have more fields in the Details table that would just have to be NULL when the Parent ID is not '0' .. fields that would just end up containing redundant data such as contact_id, group_id, topic, and other information that will remain the same througout every detail of 1 issue.
Keep in mind that I need to optimize this for being able to query the most specific information as opposed to performance . .. however performance is nice too.
----------------------------
If you've read this far I really thank you and hope you will share your thoughts =)
Thanks!