Designing a Database That Can Grow with Your System

The preceding example demonstrated that data can be standardized but did not allow for the fact that not all forms of data can fit into this standard structure. Say, for example, that you needed to add a location to the CMS events. Many news articles could use this field, but many would not. In a simple example like this, the problem may not have any practical impact; the articles that don't have a location could simply ignore this field. In a more complex, real-world example, this issue can compound and create more complex issues than the original structure resolves.

The traditional approach to this challenge is to create user-defined fields. A commercial CMS database I recently worked with had one large content table that had several extra fields of each data type: date_1, date_2, text_1, and so on. This solution does allow for future growth but has many serious issues, including:

• What do you do when you need more than two date fields?

• How will the next developer who takes over the project know what the text_2 field is in different contexts?

One solution to this challenge is the node pattern (Figure 5-1). This consists of two components: pages that are the main container and content nodes that are the actual blocks of content. A given page can have any number of content nodes.

■ Note You may notice that the node pattern, as I refer to it, is very similar to the EAV database pattern. The one difference is the fact that the node pattern uses concrete tables, which can improve performance.

For example, a simple page might have two nodes, the headline and content. A more complicated example might be a blog post that has a headline, teaser, image, and content.

Figure 5-1. The content node pattern

The key of this pattern is the fact that since any page can have any number of content nodes, the same database tables can serve the simple page, a blog page, or any other page. The abstract nature of the relationship between the CMS and its underlying data makes it possible to make substantial changes in your site structure without altering the database.

■ Note Pages can contain other pages using the structure that we are developing.

0 0

Post a comment

  • Receive news updates via email from this site