开发者

Thoughts/Input about Database Design for a CMS

开发者 https://www.devze.com 2022-12-31 20:22 出处:网络
I\'m just about to expand the functionality of our own CMS but was thinking of restructuring the database to make it simpler to add/edit data types and values.

I'm just about to expand the functionality of our own CMS but was thinking of restructuring the database to make it simpler to add/edit data types and values.

Currently, the CMS is quite flat - the CMS requires a field in the database for every type of stored value (manually created).

The first option that comes to mind is simply a table which keeps the data types (ie: Address 1, Suburb, Email Address开发者_StackOverflow etc) and another table which holds values for each of these data types. Just like how Wordpress keeps values in the 'options' table, PHP serialize would be used to store an array of values.

The second option is how Drupal works, the CMS creates tables for every data type. Unlike Wordpress, this can be a bit of an overkill but really useful for SQL queries when ordering and grouping by a particular value.

What's everyone's thoughts?


In my opinion, you should avoid serialization where possible. Your relational database should be relational, and thus be structured as such. This would include the 'Drupal Method', e.g. one table per data type. This also keeps your database healthy in a sense that it can be indexed en easily queried upon.


Unless you plan to have lots of different data types that will be added in the future which are unknown now, this is not really going to help you and would be overkill. If you have very wide tables and lots of holes in your data (i.e. lots of columns that seem to be NULL at random) then that is a pattern that is screaming to maybe have a seperate table for data that may only belong to certain entries.

Keep it simple and logical. Don't abstract for the sake of abstraction. Indeed, storing integers is cheaper with regards to storage space but unless that is a problem then don't do it in this case.

0

精彩评论

暂无评论...
验证码 换一张
取 消