I apologise for the long-winded, rantyness of this but I'm up at 3am dreading having to go to work tomorrow and deal with this database... it just feels wrong but maybe I'm wrong and just like things done my way... Please tell me what you think.
Our database schema looks something like:
page: id, label, contentid, parentpageid
content: id, xmldata
We have about 4000 entries in the page table...
I have included a vastly simplified page hierarchy which looks something like the code listing at the bottom of this post.
The source of the problem is the fact the database is fraught with things like this:
- For every single 'page' with 'label' SET (there are 3) there are 16 children, each labeled with SECTION numbers.
- Every single SECTION has a child with the name 'About' and a child with the name 'Info'
- Every single 'About' page has a set of children labeled: 'About Things', 'About Stuff' and 'About Other Stuff'
Note although the children are labeled the same, they will likely have different (but similar) content.
I have a few major problems with this schema, considering the data, and I'd like to know if I'm justified, and if there's a good solution or something I should read.
The main problem is: There are a -lot- of duplicate entries and duplicate hierarchies.
edit: Another issue is, if a page has children, it's contentid is ignored. Wasted space?
I'm also having trouble with the fact that it's hard to figure out WHERE I am in the tree... what type of object am I looking at?
For example, the TASK nodes need to be displayed differently than other nodes... and the only way to figure out if the node is a task, is if it's parent's label is "Tasks" (or "Jobs" or "ToDo"). I tried using the 'depth' of the node, but this doesn't work because sometimes other items requiring a different display on the same depth.
The solution proposed was the addition of a "Type" field... and then the UI decides how to display a node (eg 'Nav' nodes go in the main tab bar (eg About) and the Task type nodes a dropdown in the sidebar), but again, this doesn't feel right either.
Also, currently there is NO method to sort the items. We've just been lucky so far that the data went into the database in the right order they want to display it, and there have been no deletions so far.
They want to add a 'sort order' field to fix this. it seems like a lot of manual work to set up, especially if they ever want to reorder a specific menu set... (eg insert a new child to every single About node), although I guess a simple script could be written do it... though my argument is that i should be able to change it in one location and then it's just done.
I've never seen a database set up like this, but they claim, this is how all databases are set up. It's what they are for. Am i going crazy or is this a ridiculous way to set up any database with this much duplicated hierarchy (also keep in mind the below hierarchy has many less duplicate entries and duplicate trees than the real page hierarchy).
Honestly, I'd like to suggest a better solution but I'm not really sure what that is because in the real hierarchy there are 8 different types of 'About' style nodes, some of which contain more nodes with more children... but the children's labels and ordering are always in the same pattern. Do I need to create a table for each of these types of pages?
I've noticed this also appears to be a common problem for websites, where they might have a bunch of pages, all with the exact same set of children... but no way to say: ok i want this page to inherit this set of children, but i want them to all have different content. now I want to rearrange the children in one location and have them all update. Is there a robust, simple way to solve this?
SET1
SECTION1
-About
-About Things
-About Stuff
-About Other Stuff
-Info
-Tasks
-A
-B
-C
...
-H
-Data
SECTION2
-About
-About Things
-About Stuff
-About Other Stuff
-Info
-Tasks
-A
-B
-C
...
-H
-Data
...
SECTION16
SET2
SECTION1
-About
-About Things
-About Stuff
-About Other Stuff
-Info
-Jobs
-1
-2
-3
...
-8
-ToDo
-A
-B
-C
...
-H
-Other Data
SECTION2
-About
-About Things
-About Stuff
-About Other Stuff
-Info
-Jobs
-1
-2
-3
...
-8
-ToDo
-A
-B
-C
...
-H
-Other Data
SET3 (Exact same setup as SET2)
...
THANKS!